1

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.

1 Answer 1

1

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>
4
  • 2
    query_posts() should never be used for creating secondary loops When should you use wp_query vs query_posts?.
    – Rarst
    Oct 5, 2010 at 17:04
  • Good point! I've updated to use wp_query
    – abrudtkuhl
    Oct 7, 2010 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, 2010 at 3:54
  • Good point - I'll refactor and post it here... didn't even think of that :)
    – abrudtkuhl
    Oct 19, 2010 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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