Wordpress - Custom loop


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

Creates custom loop to avoid interfeering with the loop of the page


Copy this code and paste it in your HTML
  1. <h3>Recent Articles</h3>
  2. <ul>
  3. <?php
  4. $recentPosts = new WP_Query();
  5. $recentPosts->query('showposts=5');
  6. ?>
  7. <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
  8. <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
  9. <?php endwhile; ?>
  10. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.