Education theme homepage blog – would like ONLY one CATEGORY, one post to show

Community Forums Forums General Discussion Education theme homepage blog – would like ONLY one CATEGORY, one post to show

This topic is: not resolved

This topic contains 11 replies, has 5 voices, and was last updated by  abbypanda 11 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #50466

    webcami
    Participant

    Hello,

    I would like the homepage on the EDUCATION THEME to only show ONE category on the homepage blog feed, and only ONE post at a time.

    Is there a way to set that up?

    In the link attached, you see TWO volunteer opportunity posts and ONE Principal’s Newsletter. I would like to limit this to the CATEGORY Principal’s Newsletter and set it to only show ONE at a time.

    Any help is greatly appreciated!

    http://westseattlewordpress.com/olg/
    #50710

    AC
    Blocked

    I found this “hack” on Bill Erickson’s website. He said to add this to the bottom of your Functions.php file:

    /**
    * Limit homepage to one category
    *
    */
    function be_home_query( $query ) {
    if( $query->is_main_query() && $query->is_home() && !is_admin() )
    $query->set( ‘category_name’, ‘sample-category’ );
    }
    add_action( ‘pre_get_posts’, ‘be_home_query’ );

    Where you see the words ‘sample-category’ – change that to your Category “slug” and then save it.

    #54255

    webcami
    Participant

    This didn’t work. Would love a link to the original source. It hosed my php file.

    #54258

    webcami
    Participant

    Hey! I found the original!

    /**
    * Limit homepage to one category
    *
    */
    function be_home_query( $query ) {
    if( $query->is_main_query() && $query->is_home() && !is_admin() )
    $query->set( ‘category_name’, ‘sample-category’ );
    }
    add_action( ‘pre_get_posts’, ‘be_home_query’ );

    I replaced ‘sample-category’ with the NAME of the SLUG I wanted to show, in this case ‘principals-newsletter’

    THANK YOU VERY MUCH!

    #54273

    AC
    Blocked

    Glad it worked. Sometimes copying code into the forum get’s recoded or code get’s deleted.

    #55431

    archers
    Participant

    Thanks… it helped me too !!!

    #88632

    carrie
    Participant

    Hi there, I can’t seem to get it to work – I want to limit it to 3 categories. Here is my code:

    /**
    * Limit homepage to one category
    *
    */
    function be_home_query( $query ) {
    if( $query->is_main_query() && $query->is_home() && !is_admin() )
    $query->set( ‘category_name’, ‘upcoming-events’, ‘news’, ‘member-messages’ );
    }
    add_action( ‘pre_get_posts’, ‘be_home_query’ );

    url:

    Thanks,
    Carrie

    #88633

    carrie
    Participant

    Oops, here’s the url: http://www.paramedicchiefs.ca/

    • This reply was modified 1 year ago by  carrie.
    • This reply was modified 1 year ago by  carrie.
    #91539

    webcami
    Participant

    I’m sorry I didn’t see this sooner. What if you make ONE category to use for all three, such as ‘mainposts’ and set the code up exactly as is for that one category. I’m sure it’s the three mentions of categories that are causing it not to work. It could be a work around for you.

    #91672

    carrie
    Participant

    Hey Webcami, thanks for your response! I figured it out…

    function be_home_query( $query ) {
    if( $query->is_main_query() && $query->is_home() && !is_admin() )
    $query->set( ‘category_name’, ‘upcoming-events, news, member-messages’ );
    }
    add_action( ‘pre_get_posts’, ‘be_home_query’ );

    Cheers,
    Carrie

    #91675

    webcami
    Participant

    Great. Thanks for sharing it!

    #99001

    abbypanda
    Participant

    I have tried all of the suggestions here. Teh first messed up my site. Webcamis didnt mess it up but it didnt do anything. Please help? http://www.revolutionmixedmartialarts.com trying to only show “success stories”

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.