Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi I need to display posts in a category on my page template. How can I do this? Thanks

share|improve this question
    
see this: wordpress.stackexchange.com/a/3667/19691 –  atmon3r Aug 26 '12 at 9:41
add comment

3 Answers 3

Codex

Just take a look at the WordPress Template Hierarchy.

Templates

You'll find out that WordPress has three different types of templates, that you can use:

A) For built in taxonomies: Category & Tag

B) For custom taxonomies.

The template engine will search for such templates when you request a category/tag/custom taxonomy archive page.

  • taxonomy-{$taxonomy_slug}-{$term}.php
    • » taxonomy-{$taxonomy_slug}.php
    • » taxonomy.php
  • category-{$slug}.php
    • » category-{$id}.php
    • » category.php
  • tag-{$slug}.php
    • » tag-{$id}.php
    • » tag.php

Overview

Template Hierarchy by Chip Bennet

The excellent diagramm by our man Chip Bennet.

share|improve this answer
add comment

I'm reading this to say you want to add a list of category posts on a page view, not a single post view. That being the case I would first suggest looking at one of what I imagine are numerous plugins that can provide this functionality.

An example plugin would be BNS Featured Category* which provides a shortcode that should accomplish what you are looking to do.

Link: BNS Featured Category on WordPress Extend

*NB: Full disclosure, I wrote BNS Featured Category.

share|improve this answer
add comment

Try using child theme. Create a custom template and try the following code.

<?php
/*
  Template Name: template name
 */
?>
<?php get_header();
        $recent = new WP_Query("category_name="categoryname"&posts_per_page=5"); 
        while($recent->have_posts()):$recent->the_post();?>

        <?php the_content(); 

        endwhile;


 get_footer();
 ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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