WordPress home Page How to implement category display articles

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.