Created
September 26, 2013 13:42
-
-
Save rfvcorreia/6714394 to your computer and use it in GitHub Desktop.
Get Sticky Posts, if not enough get latest posts
This file contains hidden or 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
| <?php | |
| $sticky = get_option( 'sticky_posts' ); | |
| $total = 6; | |
| $featured_args = array( | |
| 'posts_per_page' => $total, | |
| 'post__in' => $sticky, | |
| 'post_status' => 'publish', | |
| 'no_found_rows' => true | |
| ); | |
| // The Featured Posts query. | |
| $featured = new WP_Query( $featured_args ); | |
| while ( $featured->have_posts() ) : $featured->the_post(); | |
| //Post Content | |
| endwhile; | |
| if ( count( $featured->posts ) < $total ) { | |
| //Get remaining non-sticky posts | |
| $nonstickyTotal = $total - count( $featured->posts ); | |
| $remaining_args = array( | |
| 'posts_per_page' => $nonstickyTotal, | |
| 'post__not_in' => $sticky, | |
| 'post_status' => 'publish', | |
| 'no_found_rows' => true | |
| ); | |
| // The Featured Posts query. | |
| $featured = new WP_Query( $remaining_args ); | |
| while ( $featured->have_posts() ) : $featured->the_post(); | |
| //Post Content | |
| endwhile; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment