peeves6
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Suburbia theme – sticky post problemThere is another way of manipulating the sticky posts within Suburbia theme.
This is by using the function is_sticky($post->ID)
As per WordPress Codex, query_posts is not efficient or recommended. The SQL query fetching yours posts has already been performed when home.php is displayed.
So remove the query_posts call, use the while loop and add the if statement to check if post is sticky or not. Run the while loop twice, once for displayed sticky posts and a second time for displaying non sticky posts.
<!– LOOP1 Sticky Posts –>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?><!– Check if sticky post –>
<?php if (is_sticky($post->ID)) : ?>
//leave the post two display code as is<?php else : ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>then,
<!– LOOP2 Non sticky posts –>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?><!– Check if not a sticky post –>
<?php if (!is_sticky($post->ID)) : ?>Remove call to query_posts and also reset query.
Add to above any extra code to display only x number of sticky or non sticky posts on the page.The advantage is that with query_posts you are making two extra DB calls, once to retrieve sticky posts and another time to retrieve non sticky posts. With the above, you dont have that anymore.
It seems to work for me…