我有一个事件页面,我想为其添加分页。然而,由于它是自定义帖子类型,我发现它相当困难。我已经成功地为我的新闻页面提供分页,但我无法为事件页面获得相同的结果。这是我的事件页面代码
<?php
get_header();
get_sidebar('left');
?>
<article class="content-main events" role="main" id="post-<?php the_ID() ?>">
<?php include 'breadcrumbs.php'; ?>
<?php query_posts(array('posts_per_page'=>'2')); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="news-post">
<h1><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h1>
<?php the_excerpt() ?>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<!--Pagination-->
<?php echo paginate_links( $args ) ?>
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
</article><!-- //.content-main -->
<?php
get_footer();
如果我尝试改变这个
<?php query_posts(array('posts_per_page'=>'2')); ?>
到此
<?php query_posts(array('category_name'=>'events','posts_per_page'=>'2')); ?>
这也不起作用。但是,如果我完全删除该行,它会显示新闻帖子类型。我被难住了!
最佳答案
自定义帖子类型的分页应与普通帖子相同。
如果你看一下默认主题 TwentyEleven你可以看到他们是如何做到的。
基本上,他们使用 next_posts_link() 和 previous_posts_link() 函数。
你可以在functions.php中查看> twentytwelve_content_nav();
干杯,
关于wordpress - 在 WordPress 中为自定义帖子类型创建分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12955950/