Archived topic
Sticky posts (or specific categories) in footer widget on home page
4 replies · Started by Delia on September 2, 2016
Hi Tom
I've been browsing through the forum but can't work out exactly what I need to do. I'm afraid I'm a bit of a newbie!
One of your replies has the below code for putting specific categories of post on the home page. I've activated the Code Snippets plugin and my category name is Company Updates. I'd like to put these categories of posts in my footer widget 4 on my home page which is set to show recent posts. Is there a way to code this? Alternatively is there a post plugin which would work well with the footer widget? Ideally, I'd like to be able to specify post numbers or sticky posts but categories could be a workaround.
Thank you so much.
function generate_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'category_name', 'home-category-slug' );
}
}
add_action( 'pre_get_posts', 'generate_home_category' );
My version:
function generate_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'Company Updates', 'company-updates' );
}
}
add_action( 'pre_get_posts', 'generate_home_category' );
Hi Tom, it has just occurred to me that I could just add the links to my key posts (which are our top FAQ questions) in the custom menu of quick links that I have in another footer! Apologies! Would still be interested if there is a way to pull in the recent Company Updates posts automatically, though.
I think you should definitely try this:
https://wordpress.org/plugins/recent-posts-widget-extended/
It does exactly what you need. :-)
That plugin should work perfectly for you :) Thanks Roberto!
Thanks so much both of you - it's always great to get a recommendation as there are so many plugins out there!