Want to just show just your sticky posts in a WordPress template? This guide tells you how (and much more) – but you’re hacking a theme and are stuck when it says “add this code before the loop” – well the loop is the bit that starts  if (have_posts()).

In the below example I’m hacking the soon-to-be-defunct default Kubric theme…

Add the following

// this line gets just the sticky posts:
query_posts(array('post__in'=>get_option('sticky_posts')));

// The Loop:
if (have_posts()) : while (have_posts()) : the_post(); 

Last Updated on