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.
Wanna read just the code? Here’s the Gist.
Implement sticky post class
- Put glckprss-sticky-posts.php into your-theme/inc.
- In functions.php call:
require get_template_directory() . '/inc/GlckPrss-Sticky-Posts.php';
- Anywhere in your theme templates do
echo glckprss_sticky_posts()to display sticky posts query.
No need to edit the actual class.