Set the method for WordPress website to specify that the classified content will not be displayed on the home page

Sometimes, for the needs of specific content, we hope that the content of a certain category will not be displayed on the first page of WordPress, but on the second page. It’s just that a certain site of we needs such a function, so this method should be sorted out and shared in the blog, so that direct replication can be used in the future.

First, revision index.php

<?php if ( have_ posts() ) : query_ posts($query_ string .’&cat=-20,-22′);
while ( have_ posts() ) : the_ post(); ?>

Directly on the front page of the current theme template index.php Modify the call out code in. For example, in the above code, 20 and 22 categories are not displayed.

Second functions.php Modification

This method is relatively good and is recommended.

/ / exclude some categories from the home page < br >function exclude_ category_ home( $query ) {
if ( $query->is_ home ) {
$query – & gt; set (‘cat ‘,’ – 20, – 22 ‘); / / category ID you want to exclude < br > 0}
return $query;

add_ filter( ‘pre_ get_ posts’, ‘exclude_ category_ home’ );

This method will not have any page vacancy problem directly, and will not appear in the latest content. Directly in the functions.php Add the above script and modify the corresponding category exclusion.

Related Article
Add article browsing history function to WordPress

This article was last updated on January 22, 2014. It has not been updated for more than three years. If Read more

Remove the default link function of WordPress upload image

Our friends have found out when using WordPress program that if there is no manually set link for the uploaded Read more

WordPress excludes the specified articles / categories from being displayed by on-site search

WordPress is the most used CMS program at present. As long as we need some functions, we can basically search Read more

WordPress common template function reference document

Basic template filefile namedescribe style.css Theme style file index.php Home page template file header.php Header template file single.php Single article Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image