Support » Fixing WordPress » include all posts, titles, etc from one category into a Page

  • I have been searching for days for an answer to a problem, and in my searches have found others wanting the answer. No answer is ever really given in any of the threads.

    How can I easily have a page, other than the posts page, list all the posts (formatted as they are on the Main blog page) pulled from a certain category and placed into on another one of my pages?

    So, If I have and that is my main blog. Lets say I have three other pages… “Outdoors”, “Photos” and “Bio”. I want all the posts on the main page from the category “outdoors” to be inserted into the “Outdoor” page. What is the code?

    Don’t you enter something like [category:19]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Wouldn’t a specific category page be better? Why output the posts onto a WP page?

    For each page you create a template, and use a query posts to include that category. When you create the “Outdoors” page, from the attributes, you select the “Outdoors” template.

    To create the template, make a copy of index.php of your theme, and rename it outdoors.php. At the very top add

    <?php /*
    	Template Name: Outdoors
    */ ?>

    Then in the part that calls the loop, insert the query to display only that category, in between “if have posts” and “while have posts”, like this

    <?php if(have_posts()) : ?>
       if (is_page()) {
    		<?php while(have_posts()) : the_post(); ?>

    Replace 3 with your appropriate category number for the ourdoors category.
    Repeat the process for the other pages.

    If you need the main loop to exclude those categories, you can use on index.php of your theme, either

    <?php if(have_posts()) : ?>
    		<?php while(have_posts()) : the_post(); ?>
    		<!-- If the post is in the category we want to exclude, we simply pass to the next post. -->
    <?php if ($postnum == 1 ) { ?>
    // My content
    <?php } ?>
     <?php if (in_category('3,4,5')) {$postnum = 0; continue; }

    again, replacing with the appropriate category numbers

    or, follow these instructions

    Hope this helps!

    Thanks Buddha Trance. I will dig into this tomorrow. Looks like something I can handle.

    Justin Tadlock


    WordPress God

    How can I easily have a page, other than the posts page, list all the posts (formatted as they are on the Main blog page) pulled from a certain category and placed into on another one of my pages?

    This already exists — Category Archives. Creating an additional page template for this only creates duplicate content on your blog.

    Ok… I deleted everything between those tags and placed your code in. It worked like a charm except for one thing. Nothing that I have typed into the actual OUTDOOR page shows up, only the posts. Not sure what I need to put back.

    If it helps, I am using the atahuapa theme version 3.2. Any ideas?

    @ greenshady – there is a very specific use for pulling posts of a category into a separate page and taking them out from the main loop. It’s like creating a different section on the site, where you don’t want all the categories to display on the home page. This is different than the archives. This is useful for blogs with separate topics that need to be organized, rather than having one loop. I am using it on my site as well.

    This doesn’t create a duplicate content problem, other than it normally would. There is no difference if the post appears on the main loop, or a separate loop. You are just moving the location of the output. To really avoid duplicate content, it’s good to use All in One SEO, or to add some lines to robots.txt

    @ theluminousroom – To add extra (static) content, you edit the template you used to create that page. The page is basically pulling a duplicate of index.php for that category, so you edit it, just as you would to add content other than the loop on the front page. Hope this helps!

    So I have created a few pages this way now and it works wonderfully for the separated posts. However, I still can’t figure how to get the stuff I type into the page editor to show up at the top before the posts. Is there a specific code to make this happen?

    I realize that the main blog is the same way, but there must be a set of commands to make the text I have typed in show up… OR… maybe I am stuck with just using an announcement post like I did on my main blog.

    Any suggestions?

    You have two options:

    1 – you create a sticky post, that will always appear at the top

    2 – (this is what I have done) You add that static content in a <div> directly in the template file that you created, before the code calling the loop. You don’t enter it on the page, or it won’t display. The page serves the purpose of calling the template only.

    For those interested, here’s a third option:

    In your template, retain ‘The Loop’ for your page. This will give you a normal page with the page text at the top.

    insert this piece of php code:

    <?php query_posts('category_name=photography&showposts=10'); ?>

    now call ‘The Loop’ for the index page. This will list all the posts in the ‘photography’ category.

    Not a very lucid explanation, I’m afraid, but hopefully it will provide the building blocks!

    buddha trance,
    just wanted to say thanks. Been looking for a plugin to do this and hadn’t found what I wanted. Your explanation was clear, simple, and works like a champ.


    I guess I do have a slight problem. Following the instructions above, I was able to create a new page that looks great, just as I want it, only showing posts from a single category. But I’ve got my theme set to show 4 posts per page. When I click on the ‘previous entries’ at the bottom of my newly created page, it shows the same 4 entries, not the 4 previous ones from that category.

    This works fine on the main blog page where clicking on ‘previous entries’ actually does bring up a page of previous entries. Since I just copied the Main Index template and added the code suggested above, I’m at a loss as to how to fix this. And if you couldn’t tell, I am not a coder and while I could follow the instructions above, I don’t know anything about php.

    Any guidance is appreciated. If you want to see the issue, the site is The single category page I created can be found by clicking on the DaveTV tab at the top of the page.


Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘include all posts, titles, etc from one category into a Page’ is closed to new replies.