If you want to display only the articles of the specified category on the homepage, the method found online is
……循环体结构代码……
But my homepage is a page to show an article, using this method, if I have four articles, two is diary class, two is not the class, although the homepage does show the diary class, but page number display is 4 pages, ask this page number problem how to solve?
Reply content:
If you want to display only the articles of the specified category on the homepage, the method found online is
……循环体结构代码……
But my homepage is a page to show an article, using this method, if I have four articles, two is diary class, two is not the class, although the homepage does show the diary class, but page number display is 4 pages, ask this page number problem how to solve?
This should be the case:
add_action( 'pre_get_posts', 'wpdit_pre_get_posts' );function wpdit_pre_get_posts( $wp_query ) { if ( is_home() || is_front_page() ){ $wp_query->set( 'category__in', array(1) ); } return $wp_query;}
Your requirement is "the first page only displays the article of the specified category", so we should only get the articles under the specified category in the first page;
Instead of presenting all the articles to determine which one to display or not to display on the homepage.