'2')); ?-6ren">
gpt4 book ai didi

wordpress - 在 Wordpress 中为自定义帖子类型创建分页

转载 作者:行者123 更新时间:2023-12-04 05:28:05 24 4
gpt4 key购买 nike

我有一个事件页面,我想向其中添加分页。但是,由于它是自定义帖子类型,我发现它相当困难。我已设法为我的新闻页面设置分页,但我无法为事件页面获得相同的结果。这是我的事件页面代码

<?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> 中查看2012_content_nav();

干杯,

关于wordpress - 在 Wordpress 中为自定义帖子类型创建分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12955950/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com