WordPress.org

Ready to get started?Download WordPress

Forums

[ Theme: Simple Catch ] Need help how showing only one category on the home page (9 posts)

  1. Ardiansyah
    Member
    Posted 2 years ago #

    Hi i'm using the Simple Catch theme. By default this theme showing all categories on the home page. But i want only one category of post to be displayed on the home page. Can you help me, please... (I am sorry to be poor at English. Thank you.) :)

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this in your theme's functions.php:

    function my_home_query( $query ) {
      // not an admin page and is the main query
      if (!is_admin() && $query->is_main_query()){
    
        if(is_home()){
          // show only category id 22 posts on the home page
          $query->set('cat', 22);
        }
      }
    
    }
    add_action( 'pre_get_posts', 'my_home_query' );

    And change $query->set('cat', 22); to the correct category ID you want to show on the home page.

  3. Ardiansyah
    Member
    Posted 2 years ago #

    @keesiemeijer: thank you, bro ... it's work :D

  4. ronakagrawal
    Member
    Posted 2 years ago #

    Can u tell me which file should i edit.
    I am not getting it.
    I added the above code and my server went out.

  5. keesiemeijer
    moderator
    Posted 2 years ago #

    Can u tell me which file should i edit.

    your theme's functions.php.

    I added the above code and my server went out.

    Where did you put it?

  6. ronakagrawal
    Member
    Posted 2 years ago #

    at the end just above the closin of php

  7. ronakagrawal
    Member
    Posted 2 years ago #

    in the funcitons.php

  8. keesiemeijer
    moderator
    Posted 2 years ago #

    Can you paste and submit the full code of your functions.php into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  9. Catch Themes
    Member
    Posted 2 years ago #

    Hi Ronak,

    It should be working fine and thank Kessiemeijer for answering this question.

    Yes, past your code and if still problem then email us by filling in the contact form in http://catchthemes.com

    Regards,
    Sakin

Topic Closed

This topic has been closed to new replies.

About this Topic