我正在尝试将分页添加到存档模板中。如果我使用与我的主博客模板相同的代码,它不会根据URL中的标记过滤结果,而是简单地显示所有帖子。对大多数人来说可能很明显,但很明显我遗漏了一些东西。
我使用以下代码获得了只显示相关帖子的归档页面(但不包含分页):
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col span_1_of_1 border_bottom">
<h3 class="subtitle no_margin_bottom"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p class="blog_meta_information date">
Author: <a href="<?php echo get_author_posts_url( get_the_author_meta( \'ID\' ), get_the_author_meta( \'user_nicename\' ) ); ?>"><?php the_author(); ?></a>
|
Date: <?php the_time(\'jS F Y\') ?>
<?php if(has_tag()) { ?>
<br>
Tags: <?php the_tags( \'\',\', \',\'\' ); ?>
<?php } else {} ?>
</p>
<p><?php the_field(\'introduction\'); ?></p>
<a href="<?php the_permalink(); ?>">Read more</a>
</div>
<?php endwhile; endif; wp_reset_postdata(); ?>
我的主要博客也使用以下代码进行分页:
<?php
$paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1;
$custom_args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 10,
\'paged\' => $paged
);
$custom_query = new WP_Query( $custom_args );
?>
<?php if( $custom_query->have_posts() ) : while( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<div class="col span_1_of_1 border_bottom">
<h3 class="subtitle no_margin_bottom"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p class="blog_meta_information date">
Author: <a href="<?php echo get_author_posts_url( get_the_author_meta( \'ID\' ), get_the_author_meta( \'user_nicename\' ) ); ?>"><?php the_author(); ?></a>
|
Date: <?php the_time(\'jS F Y\') ?>
<?php if(has_tag()) { ?>
<br>
Tags: <?php the_tags( \'\',\', \',\'\' ); ?>
<?php } else {} ?>
</p>
<p><?php the_field(\'introduction\'); ?></p>
<a href="<?php the_permalink(); ?>">Read more</a>
</div>
<?php endwhile; endif; wp_reset_postdata(); ?>
<!-- PAGINATION -->
<?php
if (function_exists(custom_pagination)) {
custom_pagination($custom_query->max_num_pages,"",$paged);
}
?>
上面还使用了我函数中的以下代码。php文件:
// PAGINATION
function custom_pagination($numpages = \'\', $pagerange = \'\', $paged=\'\') {
if (empty($pagerange)) {
$pagerange = 2;
}
/**
* This first part of our function is a fallback
* for custom pagination inside a regular loop that
* uses the global $paged and global $wp_query variables.
*
* It\'s good because we can now override default pagination
* in our theme, and use this function in default queries
* and custom queries.
*/
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == \'\') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
/**
* We construct the pagination arguments to enter into our paginate_links
* function.
*/
$pagination_args = array(
\'base\' => get_pagenum_link(1) . \'%_%\',
\'format\' => \'page/%#%\',
\'total\' => $numpages,
\'current\' => $paged,
\'show_all\' => False,
\'end_size\' => 1,
\'mid_size\' => $pagerange,
\'prev_next\' => True,
\'prev_text\' => __(\'«\'),
\'next_text\' => __(\'»\'),
\'type\' => \'plain\',
\'add_args\' => false,
\'add_fragment\' => \'\'
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<div class=\'custom-pagination\'>";
echo "<span class=\'page-numbers page-num\'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</div>";
}
}
有人知道我如何添加并使此分页也适用于我的存档模板吗?
提前感谢,
汤姆