Breaking News
You are here : Home / Wordpress / Make Sticky Post the First Post In WordPress Loop
Sticky Post First Post On wordpress Loop

Make Sticky Post the First Post In WordPress Loop

Make Sticky Post the First Post In WordPress Loop –

Hello Guys ! few days back a got a wordpress project ..where the default wordpress loop was not able to make sticky post on the top instead the sticky posts were in between the ordinary posts ,But the Requirement was to make sticky post on top of the wordpress loop.

So in-order to attain this functionality i researched a finally find our a conclusion that instead of running  query we need to run two queries ,One is for the sticky posts only and other for ordinary posts only , off course we’ll put sticky post on top of ordinary query.

So here is a quick fix how to make Sticky Post the first post in the WordPress Loop.

[separator /]

WordPress Sticky Post the First Post In Loop quick  Fix –

So as i suggested we gonna run two queries instead of just one .There are two ways we can do this .using Wp_query object or the alternate query_posts ,Im gonna Put down the code for both mehods below.Lets take a look

Sticky Post on top of the Loop -Using “Wp_Query” Loops –

Firstly we gonna use wp_query object and attain what we need.

These Loops Will List Sticky Post on the Top of the Ordinary Posts .

[separator /]

Sticky Post on top of the Loop -Using “query_posts” Loops –

Now we are gonna use the alternate loop which is query post.The result is same in the both.

These Are the Two methods for making Sticky posts come first on the Loop.But If you need pagination with them That gotta be problem with sticky post ,So there is a little fix for that So that Sticky posts won’t get repeated on the 2nd ,3rd and so on pages.we need to tell sticky post that if the page is first then it shows and else it wont , So that would simply be a if else it is.

The Pagination Fix for Sticky Posts –

To make Pagination work correctly and prevent sticky posts repeat on and 2nd and further pages you need to wrap the Sticky post loop inside following code-

[separator /]

I hope You liked this tiny post.I got in this situation so i think i better write the solution here.Tnx for visiting and reading this post.Stay healthy keep Visiting.

[pinterestfollow user=”ramandeep000″ /]

[separator /]

Tags : , , , ,

1 Reply

  1. Hello,
    Thanks for sharing related loop information.

Leave a Reply

Want to join the discussion ? Feel Free to contribute !