In wordpress I have a page template called news that I want to display all the posts from one category – ‘News’. I don’t want to use the category.php because there is a massive blog on the site already.
query_posts('cat=145');
while ( have_posts() ) : the_post();
//do something
endwhile;
Works fine but I have read that query_posts has drawbacks (like speed)
I tried doing this but it just showed me nothing:
while ( have_posts() ) : the_post();
if ( in_category( '145' ) ) : //also tried 'News'
//do something
Why doesn’t’ in_category work here?
please try this code:
You could WP Query for achieving your requirement.
Documentation: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Example:
Try to use get_posts() function:
Try this: