Created
November 9, 2015 14:25
-
-
Save JayWood/38453e6e0d5703485a4d to your computer and use it in GitHub Desktop.
multi-query loop
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
<?php | |
$tabs = 4; | |
for( $i = 0; $i < $tabs; $i++ ) { | |
// Use ppp for the offset, we're going to multiply this by the tabs | |
$posts_per_page = get_option( 'posts_per_page', 10 ); | |
/** | |
* Multiplies posts per page, by the current tab index we're on. | |
* | |
* WARNING: this breaks pagination - https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters | |
* Though since you're using this in tabs, I'm sure pagination isn't an issue. | |
*/ | |
$offset = $posts_per_page * $i; | |
$my_query = new WP_Query( array( | |
'category_name' => 'my_category', | |
// Offset allows you to 'pad' the posts by a number, so if the number were 10, it will skip the first 10 posts. | |
'offset' => $offset, | |
'posts_per_page' => $posts_per_page, | |
) ); | |
// Note the use of shorthand if/while statements, you can certainly use brackets instead. | |
if ( $my_query->have_posts() ) : | |
while( $my_query->have_posts() ) : $my_query->the_post(); | |
/** | |
* Notes: | |
* | |
* 1.) You do not have to 'echo get_the_post_thumbnail', I used the_post_thumbnail() instead, does the same thing, without having to use the post id. | |
* 2.) Do not 'echo the_title()', just use the_title() instead, it is an echoing statement, or use get_the_title( $post_id ) | |
* | |
*/ | |
?><li role="tab" data-toggle="tab" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail( array( 100, 100 ) ); ?> <?php the_title(); ?></li><?php | |
endwhile; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment