Last update at :2024-02-06,Edit by888u
Today I wanted to not display articles in one of my categories on the homepage. After struggling for a while, I found that there is no such plug-in, and I don’t want to install it. It will slow down the blog. I searched on Baidu and found the specific one. There are two methods. I use the second method and share it with you.
The first type
Modify index.php
Directly modify the callout code in index.php on the homepage of the current theme template. For example, in the above code, the 20 and 22 categories are not displayed.
Second type
Modify functions.php, this method is used by bloggers.
//Exclude certain categories from the home page function exclude_category_home( $query ) { if ( $query->is_home ) { $query->set( 'cat', '-20, -22' ); //The category ID you want to exclude } return $query; } add_filter( 'pre_get_posts', 'exclude_category_home' ); Just putbefore the ?> at the end of functions.php. This method will not cause any page vacancy problem, and it will not appear in the latest content. Add the above script directly to functions.php of the current theme and modify the corresponding category exclusions.
Recommended site search: the best virtual host in mainland China, renting a server, vps US server, renting a high-defense game server, ip query detailed address, agent ip purchase website, domain name information, domain name query, private server website space, domain name query ,
发表评论