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!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

Web development design is a promising career field. However, this industry also faces many challenges. As more businesses and brands turn to the online marketplace, web developers have the opportunity to demonstrate their skills and succeed in their careers. However, as demand for web development continues to grow, the number of developers is also increasing, resulting in increasingly fierce competition. But it’s exciting that if you have the talent and will, you can always find new ways to create unique designs and ideas. As a web developer, you may need to keep looking for new tools and resources. These new tools and resources not only make your job more convenient, but also improve the quality of your work, thus helping you win more business and customers. The trends of web development are constantly changing.

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

Do you want to connect your website to Yandex Webmaster Tools? Webmaster tools such as Google Search Console, Bing and Yandex can help you optimize your website, monitor traffic, manage robots.txt, check for website errors, and more. In this article, we will share how to add your WordPress website to the Yandex Webmaster Tool to monitor your search engine traffic. What is Yandex? Yandex is a popular search engine based in Russia, similar to Google and Bing. You can excel in Yandex

Do you want to know how to use cookies on your WordPress website? Cookies are useful tools for storing temporary information in users’ browsers. You can use this information to enhance the user experience through personalization and behavioral targeting. In this ultimate guide, we will show you how to set, get, and delete WordPresscookies like a professional. Note: This is an advanced tutorial. It requires you to be proficient in HTML, CSS, WordPress websites and PHP. What are cookies? Cookies are created and stored when users visit websites.

Do you need to fix HTTP image upload errors in WordPress? This error can be particularly frustrating when you create content in WordPress. This usually happens when you upload images or other files to your CMS using the built-in WordPress media library. In this article, we will show you how to easily fix HTTP image upload errors in WordPress. What is the reason for HTTP errors during WordPress media uploading? When you try to upload files to Wo using WordPress media uploader

To create an account on WordPress, simply visit its website, select the registration option, fill in the registration form, and verify your email address. Other ways to register include using a Google account or Apple ID. The benefits of signing up include creating a website, gaining features, joining the community, and gaining support.
