I have this code which shows one stick post for home page:
<?php
$sticky = get_option('sticky_posts');
rsort( $sticky );
$sticky = array_slice( $sticky, 1);
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
?>
<?php while (have_posts()) : the_post(); ?>
<div class="sticky-post-block">
...show sticky post ...
</div>
<?php endwhile; ?>
<?php } ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky = get_option('sticky_posts');
$args=array(
'caller_get_posts'=>1,
'post__not_in'=> $sticky,
'paged'=>$paged,
);
query_posts($args);
?>
<?php while (have_posts()) : the_post(); ?>
...exclude sticky post, show 4 latest posts ...
What I want to achieve here, is if no sticky post selected at all, the first query which pulls the stick posts return nothing.
Right now, the first query pulls the latest 4 posts and this makes it show a duplication of 4 posts.
I found this code in Codex but I don't how to go about "inserting my stuff" to stop sticky post and the duplication from showing in the "sticky-post-block."
quote:
To return just the first sticky post or nothing:
$sticky = get_option('sticky_posts');
$args = array(
'posts_per_page' => 1,
'post__in' => $sticky,
'caller_get_posts' => 1
);
query_posts($args);
if($sticky[0]) {
// insert here your stuff...
}