Categories and pages, can they play together?

I have solved the sidebar issue, but have another.

I have a page on a clients site that I would like them to be able to edit as normal for a Wordpress page. However I’d also like to be able to pull blog posts from a certain category and allow them to be displayed after the content of the page. Can anyone give me some pointers?

Nice one, thank you Jared :slight_smile:

Simple, you just need to create a new custom loop. Or more specifically, a custom page template. Here’s a tutorial I posted for more information on this if needed. And another tutorial [URL=“http://new2wp.com/pro/part-1-dynamic-jquery-featured-post-slider-with-or-without-javascript/”]I wrote for creating custom loops.

To create a template, you can just make a copy of your page.php file, rename it page-your_special_page.php, (make sure that when creating the page for this in the dashboard that the page slug matches your_special_page).

Then all you would need to do in the file is create a custom loop after the normal one.

For example, here’s a loop you may have for showing your page content


if (have_posts()) :
while (have_posts()) : the_post();

  // show your page stuff, title, page text etc.

endwhile;
endif;

After this part, you could add something like this:


$custom = new WP_query();
$custom->query('post_type=post&post_status=publish&posts_per_page=5&cat=CATEGORY_ID" );
if (have_posts()) : 
	while ($custom->have_posts()) : $custom->the_post();
        ?>
              // show your posts as a custom list or whatever here

         <?php
         endwhile;
endif;

posts_per_page=5 - number of posts your want to retrieve

cat=CATEGORY_ID - the ID # of the category you want posts from
OR use this instead:
cat_name=category_name - the name of your category, case sensitive

Hope this helps!