1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Show Last Post Excerpt On Any WordPress Page

wordpress under attack

So there is a little code that you can use to query the posts then show the last post on a page. in this particular code we are ordering by date and grabbing the last post that was made according to the date.

The following code will grab:

  1. The Permalink
  2. The title
  3. The Excerpt
  4. The Featured image

 

<?php $the_query = new WP_Query( 'posts_per_page=1&order=DESC&orderby=date' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

<div class="entry">
 <a href="<?php echo get_post_permalink();?>">
<h3><?php the_title(); ?></h3>

 <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
 echo '<img src="'.$feat_image.'"/>'; ?>
 <?php the_excerpt(); ?></a>
  </div>

<?php endwhile; wp_reset_postdata(); ?>

 

Please follow and like us:
Show Last Post Excerpt On Any WordPress Page was last modified: June 3rd, 2016 by Maximus Mccullough

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.