custom loop query example


/ Published in: PHP
Save to your folder(s)

the above url has some helpful parameters


Copy this code and paste it in your HTML
  1. <?php $my_query = new WP_Query('cat=3&showposts=1'); ?>
  2.  
  3. <?php if ($my_query->have_posts()) : ?>
  4.  
  5. <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
  6.  
  7. <div class="post" id="post-<?php the_ID(); ?>">
  8. <h3><?php the_title(); ?></h3>
  9. <div class="entry">
  10. <?php the_content("Continue reading " . the_title('', '', false)); ?>
  11. </div>
  12. <?php comments_template(); ?>
  13.  
  14. <?php endwhile; ?>
  15.  
  16. <div class="navigation">
  17. <div class="left"><?php previous_post_link('&laquo; Previous Posts'); ?></div>
  18. <div class="right"><?php previous_posts_link('Next Entries &raquo;') ?></div>
  19. </div>
  20.  
  21. <?php else : ?>
  22.  
  23. <h2 class="center">Not Found</h2>
  24. <p class="center">Sorry, but you are looking for something that isn't here.</p>
  25. <?php include (TEMPLATEPATH . "/searchform.php"); ?>
  26.  
  27. <?php endif; ?>

URL: http://codex.wordpress.org/index.php?title=Template_Tags/query_posts&section=11#Parameters

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.