您可以使用分页创建两个单独的循环,并将它们并排放置在div容器中,每个div中都有分页链接。您可以在每个div中包含分页链接,因为一种post类型可能比另一种多,因此页面也会比另一种多。
除非您使用ajax javascript独立刷新div的内容,否则这些列将一起分页,在这种情况下,您必须在调用中传递正确的相对页码。
如果没有ajax,使用单独的post类型列串联分页,您的模板将如下所示(未测试的代码):
<?php
/*
Template Name: Side-by-Side Paginated Custom Post Types
*/
global $query_string;
global $wp_query;
get_header();
$myquery = wp_parse_args($query_string);
$myquery[\'tax_query\'] = $wp_query->tax_query;
echo \'<div id="container">\';
// Work whether query var is page or paged
if ( get_query_var(\'paged\') )
{ $paged = get_query_var(\'paged\'); }
elseif ( get_query_var(\'page\') )
{ $paged = get_query_var(\'page\');
} else
{ $paged = 1; }
$myquery[\'post_status\'] = \'publish\';
$myquery[\'paged\'] = \'.$paged\';
// Create Page Heading, including each term from the query
// Allows for advanced tax query with more than one taxonomy term, such as News and Events in the same query
foreach ($wp_query->tax_query->queries as $taxterm) {
if (\'your_taxonomy\' == $taxterm[\'taxonomy\']) {
$last_term = end( array_keys( $taxterm[\'terms\'] ) ); // Mark the last topic
echo "<h1>";
foreach ($taxterm[\'terms\'] as $k => $termid) {
$termobj = get_term_by( $taxterm[\'field\'], $termid, $taxterm[\'taxonomy\'] );
echo $termobj->name;
if ( $k !== $last_term ) echo \' & \';
}
echo "</h1>";
}
}
echo \'<div class="left-column">\';
$myquery[\'post_type\'] = \'your_cpt_1\';
echo \'<h2 class="sec1 title">Custom Posts 1</h2>\';
// Query
$myquery = new WP_query( $args );
if ( $myquery->have_posts() ) : while ( $myquery->have_posts() ) : $myquery->the_post();
get_template_part( \'content\', \'your_cpt_1\' );
endwhile; else :
endif;
echo \'<div class="pagination">\';
echo \'<div class="alignleft">\'; previous_posts_link(\'Previous\'); echo \'</div>\';
echo \'<div class="alignright">\'; next_posts_link(\'Next\'); echo \'</div>\';
echo \'</div> <!-- end pagination -->\';
wp_reset_postdata();
echo \'</div> <!-- div class="left-column" -->\';
echo \'<div class="right-column">\';
$myquery[\'post_type\'] = \'your_cpt_2\';
echo \'<h2 class="sec1 title">Custom Posts 2</h2>\';
// Query
$myquery = new WP_query( $args );
if ( $myquery->have_posts() ) : while ( $myquery->have_posts() ) : $myquery->the_post();
get_template_part( \'content\', \'your_cpt_2\' );
endwhile; else :
endif;
echo \'<div class="pagination">\';
echo \'<div class="alignleft">\'; previous_posts_link(\'Previous\'); echo \'</div>\';
echo \'<div class="alignright">\'; next_posts_link(\'Next\'); echo \'</div>\';
echo \'</div> <!-- end pagination -->\';
wp_reset_postdata();
echo \'</div> <!-- div class="right-column" -->\';
echo \'</div> <!-- div id="container" -->\';
get_footer();
?>