Advertisement
afsarwebdev

Recent post / latest post

Feb 7th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. //Recent or latest post
  2.  
  3. <?php
  4. $recent_post_number = array( 'numberposts' => 4 );
  5. $recent_posts = wp_get_recent_posts( $recent_post_number );
  6. foreach( $recent_posts as $recent ){ ?>
  7. <?php echo '
  8. <li>
  9. <div class="media"> <a href="' . get_permalink($recent["ID"]) . '" class="media-left"> '. get_the_post_thumbnail( $post->ID, 'small' ). ' </a>
  10. <div class="media-body"> <a href="' . get_permalink($recent["ID"]) . '" class="catg_title"> '. $recent["post_title"]. '</a> </div>
  11. </div>
  12. </li>
  13. '?>
  14.  
  15. <?php } wp_reset_query(); ?>
  16.  
  17. /*Reference*/
  18.  
  19.  
  20. <h2>Recent Posts</h2>
  21. https://codex.wordpress.org/Function_Reference/wp_get_recent_posts
  22. <ul>
  23. <?php
  24. $args = array( 'numberposts' => '5' );
  25. $recent_posts = wp_get_recent_posts( $args );
  26. foreach( $recent_posts as $recent ){
  27. echo '<li><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a> </li> ';
  28. }
  29. wp_reset_query();
  30. ?>
  31. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement