Last active
November 16, 2015 16:42
-
-
Save hans2103/54b1c3e04beff3a653cd to your computer and use it in GitHub Desktop.
WordPress - display first (sticky or not) post and then the rest of all posts (sticky or not).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( is_home() && !is_paged() ) : | |
$args = array ( | |
// display the first sticky post, if none return the last post published | |
'posts_per_page' => 1, | |
'post__in' => get_option( 'sticky_posts' ), | |
'ignore_sticky_posts' => 1, | |
); | |
$query = new WP_Query( $args ); | |
while ($query->have_posts()) : $query->the_post(); | |
$do_not_duplicate = $post->ID; | |
echo '<br />'; | |
echo the_title(); | |
echo '<br />'; | |
endwhile; | |
wp_reset_query(); | |
echo '<br />'; | |
echo '<br />'; | |
$args = array ( | |
// display the rest of the posts, except for the post shown above (sticky or first) | |
'posts_per_page' => 9, | |
'ignore_sticky_posts' => 1, | |
'post__not_in' => array($do_not_duplicate) | |
); | |
$query = new WP_Query( $args ); | |
if( $query->have_posts() ) : | |
while ($query->have_posts()) : $query->the_post(); | |
if( $post->ID == $do_not_duplicate ) continue; | |
echo the_title(); | |
echo '<br />'; | |
endwhile; | |
endif; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment