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" ); 

     }
  • Please read the tag descriptions for each tag you use very carefully. Do not just throw some random tags at your questions. – fuxia Dec 12 '13 at 7:59
  • Are you referring to a category archive page? Otherwise, you can use pre_get_posts if you only want to display posts in one category on the posts page. – Brad Dalton May 20 '14 at 17:34
up vote 2 down vote accepted

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!

Go to your settings and enable permalinks. Set it to 'Post name'. Now you can just go to www.example.com/category/reviews.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.