我的主页上有一个非常好的分页,代码是:
<div class="articles">
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$query = new WP_Query( array( \'post_type\' => \'articles\', \'orderby\'=> \'menu_order\', \'posts_per_page\' => 5,\'paged\' => $paged ) );
if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="article">
<div class="entry">
<h4 class="title oswald post-title"><?php the_title(); ?></h4>
<?php the_content(); ?>
</div>
</div><!--end article-->
<hr/>
<?php endwhile; //wp_reset_postdata(); ?>
<?php else : ?>
<p>no posts</p>
<?php endif; ?>
<?php if ( function_exists( \'foundationpress_pagination\' ) ) { foundationpress_pagination(); } else if ( is_paged() ) { ?>
<nav id="post-nav">
<div class="post-previous"><?php next_posts_link( __( \'← Older posts\', \'foundationpress\' ) ); ?></div>
<div class="post-next"><?php previous_posts_link( __( \'Newer posts →\', \'foundationpress\' ) ); ?></div>
</nav>
<?php } ?>
</div>
这里是foundationpress\\u分页功能:
function foundationpress_pagination() {
global $wp_query;
$big = 999999999; // This needs to be an unlikely integer
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', html_entity_decode( get_pagenum_link( $big ) ) ),
\'current\' => max( 1, get_query_var( \'paged\' ) ),
\'total\' => $wp_query->max_num_pages,
\'mid_size\' => 5,
\'prev_next\' => true,
\'prev_text\' => __( \'«\', \'foundationpress\' ),
\'next_text\' => __( \'»\', \'foundationpress\' ),
\'type\' => \'list\',
) );
$paginate_links = str_replace( "<ul class=\'page-numbers\'>", "<ul class=\'pagination\'>", $paginate_links );
$paginate_links = str_replace( \'<li><span class="page-numbers dots">\', "<li><a href=\'#\'>", $paginate_links );
$paginate_links = str_replace( "<li><span class=\'page-numbers current\'>", "<li class=\'current\'><a href=\'#\'>", $paginate_links );
$paginate_links = str_replace( \'</span>\', \'</a>\', $paginate_links );
$paginate_links = str_replace( "<li><a href=\'#\'>…</a></li>", "<li><span class=\'dots\'>…</span></li>", $paginate_links );
$paginate_links = preg_replace( \'/\\s*page-numbers/\', \'\', $paginate_links );
// Display the pagination if more than one page is found
if ( $paginate_links ) {
echo \'<div class="pagination-centered">\';
echo $paginate_links;
echo \'</div><!--// end .pagination -->\';
}
}
在我的主题中,我制作了一个名为“page-ar.php”的页面模板,并在顶部的评论中加入模板名称:文章页面。我基本上复制了整个查询并将其粘贴到此页面上。但是,它只正确显示了前5篇文章,没有显示分页。同时输入“/第/2页”会将我发送到404页。
我真的不知道问题是什么,我希望这里有人这么做。此外,我已经将“设置”>“阅读”设置为5,所以我认为不是这样。
当我将模板页面显示为首页tho时,分页将正确显示tho(使用get\\u query\\u var(\'page\'))。但这是我唯一能让它发挥作用的方法。
作为我的家,我只使用索引。php