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.

Share:
Share on Facebook0Share on LinkedIn0Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit0

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. Required fields are marked *

Most Popular Posts

To learn MySQL PACK_KEYS with example

Posted on 3 years ago

Bhumi

How to add ColorDots in FullCalender?

Posted on 3 years ago

Bhumi

How to use MySQL Event Scheduler

Posted on 1 year ago

Bhumi

How to use PHP Method Chaining?

Posted on 3 years ago

Bhumi

How BlockChain and Ethereum works?

Updated 1 day ago

Bhumi

Facade implementation in Laravel

Updated 2 months ago

Bhumi

MySQL coalesce() function

Updated 18 years ago

Bhumi

How to use JavaScript Promise API?

Updated 18 years ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi