In order to unclutter my blog home page, I would like to display only posts from a certain category (for example “uncategorized”). Ideally I’d also like to limit the number of displayed posts to, say, 5. Is there a way to do this?
PHP isn’t my strong suit, but I managed to do this by rewriting the loop in my index.php
file:
$CATEGORIES = array('show-on-front-page');
$MAX_POSTS = 5;
/* Start the Loop */
$post_count = 0;
while ( have_posts() ) : the_post();
if ( !has_category($CATEGORIES) )
continue;
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
if ( $post_count == 0 ) {
get_template_part( 'template-parts/content-big', get_post_format() );
} else {
get_template_part( 'template-parts/content', get_post_format() );
}
$post_count = $post_count + 1;
if ( $post_count >= $MAX_POSTS )
break;
endwhile;
Hello there,
I hope you are doing well today.
I would recommend that you use the following plugin to make a child them for the code changes and make a backup:
Best Regards,
Support