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 6 months, 2 weeks ago.

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

    webcami
    Participant
    Post count: 52

    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
    Post count: 7712

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

    [php]/**
    * 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’ );[/php]

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

    #54255

    webcami
    Participant
    Post count: 52

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

    #54258

    webcami
    Participant
    Post count: 52

    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
    Post count: 7712

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

    #55431

    archers
    Participant
    Post count: 11

    Thanks… it helped me too !!!

    #88632

    carrie
    Participant
    Post count: 15

    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
    Post count: 15

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

    • This reply was modified 8 months, 3 weeks ago by  carrie.
    • This reply was modified 8 months, 3 weeks ago by  carrie.
    #91539

    webcami
    Participant
    Post count: 52

    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
    Post count: 15

    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
    Post count: 52

    Great. Thanks for sharing it!

    #99001

    abbypanda
    Participant
    Post count: 78

    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.