List of latest posts


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



Copy this code and paste it in your HTML
  1. // Function to display list of latest news articles
  2. function latest_news_list($count) {
  3. ?>
  4. <h3>latest news</h3>
  5. <ul>
  6. <?php
  7. global $post;
  8. $args = array( 'numberposts' => $count, 'offset'=> 0, 'category' => 1 );
  9. $myposts = get_posts( $args );
  10. foreach( $myposts as $post ) : setup_postdata($post); ?>
  11. <!-- <p class="date"><?php the_date(); ?></p> -->
  12. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  13. <?php endforeach; ?>
  14. </ul>
  15. <?php
  16. }
  17. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.