Community Forums › Forums › Archived Forums › General Discussion › Education theme homepage blog – would like ONLY one CATEGORY, one post to show
- This topic has 13 replies, 6 voices, and was last updated 9 years, 11 months ago by
kathyosborne.
-
AuthorPosts
-
July 12, 2013 at 3:58 pm #50466
webcami
ParticipantHello,
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/July 14, 2013 at 6:10 pm #50710AnitaC
KeymasterI 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.
Need help with customization or troubleshooting? Reach out to me.
August 5, 2013 at 11:02 am #54255webcami
ParticipantThis didn't work. Would love a link to the original source. It hosed my php file.
August 5, 2013 at 11:18 am #54258webcami
ParticipantHey! 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!
August 5, 2013 at 12:41 pm #54273AnitaC
KeymasterGlad it worked. Sometimes copying code into the forum get's recoded or code get's deleted.
Need help with customization or troubleshooting? Reach out to me.
August 10, 2013 at 7:01 am #55431archers
MemberThanks... it helped me too !!!
February 4, 2014 at 5:22 pm #88632carrie
ParticipantHi 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’ );Thanks,
CarrieFebruary 4, 2014 at 5:32 pm #88633carrie
ParticipantOops, here's the url: http://www.paramedicchiefs.ca/
February 20, 2014 at 9:14 pm #91539webcami
ParticipantI'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.
February 21, 2014 at 10:35 am #91672carrie
ParticipantHey 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,
CarrieFebruary 21, 2014 at 10:37 am #91675webcami
ParticipantGreat. Thanks for sharing it!
April 7, 2014 at 11:58 pm #99001abbypanda
MemberI 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"
March 9, 2015 at 9:49 am #143802kathyosborne
Participantthis didn't work for me. I only want my news-events showing here http://www.moii.com/newsite (Below the slider).
But all posts are still showing...
March 9, 2015 at 4:29 pm #143838kathyosborne
ParticipantI found this solution on another thread that worked for me when I added it to my functions file. Jsut an fyi if this first solution doesn't work for someone:
Exclude Categories From Home Which Show On Blog Page in Genesis
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.