Get Posts from Category


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

Useful snippet for getting a specific number of posts from a specific category, useful for news listing in sidebar


Copy this code and paste it in your HTML
  1. <ul>
  2. <?php
  3. global $post;
  4. $myposts = get_posts('numberposts=6&category=3');
  5. foreach($myposts as $post) :
  6. setup_postdata($post);
  7. ?>
  8. <li>
  9. <div class="news_ticker_articles">
  10. <p><strong> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
  11. <?php the_title(); ?>
  12. </a> </strong></p>
  13. <p class="excerpt_bottom"><? echo bm_better_excerpt(100, '...'); ?></p>
  14. </div>
  15. </li>
  16. <?php endforeach; ?>
  17. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.