Show Last Post Excerpt On Any WordPress Page

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

 

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

Only cool people share!

<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(); ?>[/code]

 

Show Last Post Excerpt On Any WordPress Page was last modified: June 3rd, 2016 by Maximus Mccullough
wordpress under attack

Leave a Reply

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