Displaying Category in sidebar post widget but not in the loop on home

I’ve seen many pages on how to exclude a category from the home page entirely.

I am setting up a site to have a widget called News that displays the latest news items on the right but it seems like overkill to have them there and in the loop going down the page as well.

This code, however, hides it from everything on the home page as does many of the plugins I could find:

function only_portfolio_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '3' );
}
}
add_action( 'pre_get_posts', 'only_portfolio_category' );

Other sites mention editing the Loop to exclude it only from the main listing but I am lost as to where in the Loop to add code to get this done and how.

Read more here: Displaying Category in sidebar post widget but not in the loop on home

Leave a Reply

Your email address will not be published. Required fields are marked *