WordPress.org

Support

Support » Themes and Templates » [ Theme: Simple Catch ] Need help how showing only one category on the home page

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

  • Ardiansyah
    Member

    @haysnaidra

    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.) 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • keesiemeijer
    moderator

    @keesiemeijer

    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.

    Ardiansyah
    Member

    @haysnaidra

    @keesiemeijer: thank you, bro … it’s work 😀

    ronakagrawal
    Member

    @ronakagrawal

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

    keesiemeijer
    moderator

    @keesiemeijer

    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?

    ronakagrawal
    Member

    @ronakagrawal

    at the end just above the closin of php

    ronakagrawal
    Member

    @ronakagrawal

    in the funcitons.php

    keesiemeijer
    moderator

    @keesiemeijer

    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.

    Catch Themes
    Participant

    @catchthemes

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[ Theme: Simple Catch ] Need help how showing only one category on the home page’ is closed to new replies.