我正在尝试将自定义存档帖子和默认帖子合并到一个我管理的存档页面上。。。有点像,但我无法使用pagenavi插件或主题默认分页代码进行分页。我尝试过使用paged,但如果有任何显示,我不确定它是否会将两个类别一起分页,或者只分页一个类别。
我需要组合两个类别,一个是自定义分类法,另一个是默认分类法,然后对它们进行不同的样式设置,在页面上有一组数量的组合帖子,并且能够将它们放在9篇帖子的页面中。
我使用的代码:
<?php if (is_category()) { ?>
<h1 class="page-title">
<span><?php _e(); ?></span> <?php single_cat_title(); ?>
</h1>
<?php } ?>
<ul>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( \'partials/loop\', \'archive\' ); ?>
<?php endwhile; ?>
</ul>
<?php rewind_posts(); ?>
<?php
$args = array(
\'post_type\' => \'events\',
\'posts_per_page\' => \'6\',
\'paged\' => $paged,
\'tax_query\' => array(
array(
\'taxonomy\' => \'event_cat\',\'events\',
\'field\' => \'slug\',
\'terms\' => \'events\',\'upcoming-events\'
)
)
);?>
<?php $the_query = new WP_Query( $args ); ?>
<ul>
<?php if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( \'partials/loop\', \'archive-events\' ); ?>
<?php endwhile; ?>
</ul>
<?php wp_pagenavi(); ?>
<?php else : ?>
<?php get_template_part( \'partials/content\', \'missing\' ); ?>
<?php endif; ?>
将上述内容更改为: <?php if (is_category()) { ?>
<h1 class="page-title">
<span><?php _e(); ?></span> <?php single_cat_title(); ?>
</h1>
<?php } ?>
<ul class="small-block-grid-1 medium-block-grid-2 large-block-grid-3">
<?php $query = new WP_Query( array( \'cat\' => \'7\' )); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( \'partials/loop\', \'archive\' ); ?>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php get_template_part( \'partials/content\', \'missing\' ); ?>
<?php endif; ?>
<?php rewind_posts(); ?>
<?php
$args = array(
\'post_type\' => \'events\',
\'posts_per_page\' => \'3\',
\'paged\' => get_query_var( \'paged\' ),
\'tax_query\' => array(
array(
\'taxonomy\' => \'event_cat\',
\'field\' => \'slug\',
\'terms\' => \'events\'
)
)
);?>
<?php $the_query = new WP_Query( $args ); ?>
<ul class="small-block-grid-1 medium-block-grid-2 large-block-grid-3">
<?php if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( \'partials/loop\', \'archive-events\' ); ?>
<?php endwhile; ?>
</ul>
<?php if (function_exists(\'joints_page_navi\')) { ?>
<?php wp_pagenavi(); ?>
<?php } else { ?>
<nav class="wp-prev-next">
<ul class="clearfix">
<li class="prev-link"><?php next_posts_link(__(\'« Older Entries\', "jointstheme")) ?></li>
<li class="next-link"><?php previous_posts_link(__(\'Newer Entries »\', "jointstheme")) ?></li>
</ul>
</nav>
<?php } ?>
<?php endif; ?>