The following WordPress tutorial column will introduce to you how WordPress filters background articles. I hope it will be helpful to friends in need!
In addition to its own article classification, wordpress also supports custom classifications, that is, you can register custom article classifications according to your own needs.
How to register your own custom taxonomy?
First open the WordPress core function file functions.php and insert the following code in the appropriate location
function my_custom_post_courses() { $labels = array( 'name' => _x( 'courses', 'post type 名称' ), 'singular_name' => _x( 'my_courses', 'post type 单个 item 时的名称'), 'add_new' => _x( '增加课程', '添加新内容的链接名称' ), 'add_new_item' => __( '增加一个课程' ), 'edit_item' => __( '编辑课程' ), 'new_item' => __( '新课程' ), 'all_items' => __( '所有课程' ), 'view_item' => __( '查看课程' ), 'search_items' => __( '搜索课程' ), 'not_found' => __( '没有找到有关课程' ), 'not_found_in_trash' => __( '回收站里面没有相关课程' ), 'parent_item_colon' => '', 'menu_name' => '课程' ); $args = array( 'labels' => $labels, 'description' => '我们网站的课程信息', 'public' => true, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), 'has_archive' => true ); register_post_type( 'my_courses', $args ); } add_action( 'init', 'my_custom_post_courses' );
In this way, we have registered a custom taxonomy named 'Course'. The next step is how to set up filtered articles.
If you have a lot of articles or products, it is necessary for us to add a filtering function to the WordPress backend article list page, as shown below:
To achieve filtering Function requires two steps
The first step is to add the background function in the functions.php file and let the list page display this category selection
add_action('restrict_manage_posts', 'mycat_add_select_int'); function mycat_add_select_int(){ global $typenow; global $wp_query; if ($typenow == 'course') { return wp_dropdown_categories(array( 'show_option_all' => '课程分类', 'taxonomy' => 'course_list', 'name' => 'course_list', 'orderby' => 'name', 'selected' => @$wp_query->query['course_list'], 'hierarchical' => true, 'depth' => 5, 'show_count' => true, 'hide_empty' => false, )); } }
The second step is to implement filtering Function
add_filter('parse_query', 'mycats_add_query_init'); function mycats_add_query_init($query){ $qv = &$query->query_vars; if (($qv['course_list']) && is_numeric($qv['course_list'])) { $term = get_term_by('id', $qv['course_list'],'course_list'); $qv['course_list'] = $term->slug; } }
Only the above two steps are needed to easily implement the background article filtering function, which is very practical for blog webmasters or webmasters with many background articles on their websites.
The above is the detailed content of How to filter taxonomy articles in WordPress?. For more information, please follow other related articles on the PHP Chinese website!

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Wix is suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.

WordPress itself is free, but it costs extra to use: 1. WordPress.com offers a package ranging from free to paid, with prices ranging from a few dollars per month to dozens of dollars; 2. WordPress.org requires purchasing a domain name (10-20 US dollars per year) and hosting services (5-50 US dollars per month); 3. Most plug-ins and themes are free, and the paid price ranges from tens to hundreds of dollars; by choosing the right hosting service, using plug-ins and themes reasonably, and regularly maintaining and optimizing, the cost of WordPress can be effectively controlled and optimized.

The core version of WordPress is free, but other fees may be incurred during use. 1. Domain names and hosting services require payment. 2. Advanced themes and plug-ins may be charged. 3. Professional services and advanced features may be charged.

WordPress is easy for beginners to get started. 1. After logging into the background, the user interface is intuitive and the simple dashboard provides all the necessary function links. 2. Basic operations include creating and editing content. The WYSIWYG editor simplifies content creation. 3. Beginners can expand website functions through plug-ins and themes, and the learning curve exists but can be mastered through practice.

People choose to use WordPress because of its power and flexibility. 1) WordPress is an open source CMS with strong ease of use and scalability, suitable for various website needs. 2) It has rich themes and plugins, a huge ecosystem and strong community support. 3) The working principle of WordPress is based on themes, plug-ins and core functions, and uses PHP and MySQL to process data, and supports performance optimization.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor