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'm looking to create a page within my site that looks like this:

Tag/Category: News
News Post a
News Post b
News Post c

Tag/Category: Events
Event a
Event b
Event c

I'm new to Wordpress. I may not have the wordpress jargon to ask this correctly. Thanks for your help.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Your best bet is to create a page template with the following code. Also you will need to decide if you will use a tag or category. The code below assumes you are using a category.

<div class="news">
<?php
  //The Query
  wp_query('showposts=5&category_name=News');

  //The Loop
  if ( have_posts() ) : while ( have_posts() ) : the_post();
  ?> 
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="post_content">
         <?php the_excerpt(); ?>    
    </div>
  <?
  endwhile; 
  endif;

  //Reset Query
  wp_reset_query();

  ?>
</div>

<div class="events">
  <?php 
    //The Query
    wp_query('showposts=5&category_name=Events');

    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?> 
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <div class="post_content">
             <?php the_excerpt(); ?>    
        </div>
    <?
    endwhile; 
    endif;

    //Reset Query
    wp_reset_query();
  ?>
</div>
share|improve this answer
2  
query_posts() should never be used for creating secondary loops When should you use wp_query vs query_posts?. –  Rarst Oct 5 '10 at 17:04
    
awesome! thanks I'll check that out –  xer0x Oct 6 '10 at 2:57
    
Good point! I've updated to use wp_query –  abrudtkuhl Oct 7 '10 at 19:24
1  
Ehm, it doesn't quite work like that. :) WP_Query is a class, it doesn't work like a drop-in replacement for a function. Please see question linked above for brief explanation and links to documentation. –  Rarst Oct 8 '10 at 3:54
    
Good point - I'll refactor and post it here... didn't even think of that :) –  abrudtkuhl Oct 19 '10 at 16:41
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.