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.

I have posts which i would like to put in to 3 categories News, Events, and Press Releases, then i have three pages which are using the same template. I would like to display those posts on to relevant pages so News posts on News page etc. Could someone tell me what would be the best way to do that.

I guess its something easy but I'm fairly new to Wordpress.

Many thanks,

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could simply use the category pages WordPress generates using the category.php template, or category-{slug}.php. If you don't like the /category/categoryname/ url format WP uses, there are a few plugins that remove the category base- I use Yoast SEO plugin for this, which gives you lots of other great features on top.

Your other option is to create a special template for these pages with some additional code to load posts from your category. The WP Codex actually has exactly this code for you already, using a custom field on each page to designate which category you'd like it to load.

share|improve this answer
    
Thanks for your replay Milo I was thinking more about approche like that if ( is_page('news') ) { query_posts('cat=7'); } elseif is_page('events') ) { query_posts('cat=9'); } <?php while (have_posts()) : the_post(); ?> <?php the_title(); ?> <?php the_content(); ?> <?php endwhile;?> but for some reason that doesn't work –  jmysona Jun 12 '11 at 12:17
    
is this the only loop on your page or are you displaying the page's content above this in the template via another loop? query_posts is for modifying the main query on a page, not for multiple loops. you'll get unpredictable results due to global variables being set up for your original query. WP_Query should be used instead for additional loops. otherwise, it should work, though paging won't unless you explicitly retrieve and pass the paged variable. again, have a look at the code I posted from the Codex, and look up the differences between query_posts and WP_Query. –  Milo Jun 12 '11 at 15:44
    
That is the only loop on that particular template –  jmysona Jun 12 '11 at 17:13
    
ok i managed to to it simply just like that '<?php if (is_page('News in brief')){ ?> <?php query_posts('posts_per_page=5&category_name=news&paged='.$paged); ?> ...' Thanks for all your help –  jmysona Jun 15 '11 at 13:51
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.