I have different categories called as reviews, ideas etc. I have a page called as review, I want to display review category to the review page (only review category). Is this possible? Which file I have to change? I have the code below, but it is displaying only the texts not any links to the posts, 7 is my category id.
if( is_page( 'reviews' )){
query_posts("cat=7" );
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
From what I understand, the question is, how can you show only one category on a WordPress Page?
What Scuba Kay is suggesting is the default category archive, if you want to go that route, WordPress already has archive pages with your posts for each category without you having to create your own Page. If you want to make changes to this archive page, you can read up on Category Templates. This will enable you to create your own template for a specific category.
If you literally want to create a WordPress Page and just call posts from a category, you can create a Page Template and use a Query similar to what you’re already doing and create your own Loop. There’s another good question on this site that explains how to pull posts using the Codex as reference.
So for example, if you’re using get_posts to call a reviews category on a Page Template, it might look something like this:
<?php
$reviewArgs = array(
'category' => '3',
'posts_per_page' => 5
);
$reviews = get_posts( $reviewArgs );
foreach ($reviews as $post) : setup_postdata($post);
the_post_thumbnail();
the_title();
the_content();
endforeach;
?>
Hope that helps!
Method 2
Go to your settings and enable permalinks. Set it to ‘Post name’. Now you can just go to www.example.com/category/reviews.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0