Sticky posts query, removed from loop


Note: Content might be outdated!

Sticky posts in WordPress are great to visually expose featured content in a theme. By default, WordPress shows posts marked as sticky at the top of the loop applying sticky as a special CSS class to post classes. Later on down the loop, they would show up again, in their natural position and without the extra class.
But we can, for fun and profit, also remove sticky post from the top of the main loop, wrap them into their own special query and print them in our theme templates using a (one) custom template tag.

Complete Gist

Wanna read just the code? Here’s the Gist.

Implement sticky post class

  1. Put glckprss-sticky-posts.php into your-theme/inc.
  2. In functions.php call:
    require get_template_directory() . '/inc/GlckPrss-Sticky-Posts.php';
  3. Anywhere in your theme templates do echo glckprss_sticky_posts() to display sticky posts query.


No need to edit the actual class.

Customize wrapping element for query template

Customize sticky posts markup