Back to Top

How to get Last Post in WordPress

Here I come with quick but useful tips in WordPress.Recently I have upgraded my blog theme and I wanted to make some changes on the last post found in the loop on the last page.So I thought is it quite difficult to get the last post?

No,It’s not difficult and specifically in WordPress if you have good knowledge of WordPress core variables and functions so simply place explained code in below.

Let’s have a look into the condition which compares the total number of posts to the current post number:

Here, Wp_query property is used to count the number of posts and $wp_query->current_post gives us the current loop number.$wp_query->post_count will give a count of posts.

That’s it.It is so simple. Now you can make layout changes for the last record of the loop.

Thanks for reading and feel free to share your thoughts, don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (2)

  1. With bountiful of new features and bug fixes, WordPress 3.5 surely made some remarkable improvements in the platform. The new update will definitely help WordPress to retain its throne in future. Kudos for the work of core developement team.

  2. Great improvements but hiding blogroll is not a good idea some blogger are still love to use those

    finally i found a fix to enable blogroll

    http://www.shoutgeek.com/enable-blogroll-links-wordpress/

Leave a Reply

Your email address will not be published.

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

Most Popular Posts

How To use Store Procedure with PDO

Posted on 12 years ago

Bhumi

How to set 301 Redirection in PHP

Posted on 8 years ago

Bhumi