[英]WordPress Pagination - Not Working - Custom Plugin
因此,我目前正在开发依赖于自定义帖子类型的自定义插件。 然后,我在管理页面中显示这些自定义帖子类型,但似乎无法显示分页! 我不知道我在做什么错。
这是我正在运行的循环:
<?php
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$mypost = array( 'posts_per_page' =>'1','paged'=>$paged,'post_type' => 'usernotes', 'meta_query' => array(
array(
'key' => 'userNotesID',
'value' => get_current_user_id( )
)
));
$loop = new WP_Query( $mypost );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<section class="innerWrapper">
<article id="<?php the_ID(); ?>" class="note" <?php post_class(); ?>>
<header class="entry-header">
<!-- Display Title and Author Name -->
<span class="title"><?php the_title(); ?></span>
<span class="date"><?php the_time(get_option('date_format')); ?></span>
</header>
<div class="noteInner">
<?php the_content(); ?>
</div>
<footer>
<a href="'#" class="delete button-red" id="<?php the_ID(); ?>">Hide Note</a>
<div class="clear"></div>
</footer>
</article>
</section>
<?php endwhile; ?>
它按应显示1个帖子,如果我将posts_per_page增加到2,则应显示2个帖子。 问题是我无法获得任何分页链接。 如果我将其设置为1,然后导航到?paged = 2,则没有任何变化,它仅显示第一篇文章! 知道为什么或可以尝试什么吗?
编辑:
可能应该在管理页面上添加此内容,以显示自定义帖子类型。
在查询中使用“当前”属性该怎么办? 如
'current' => max( 1, get_query_var('paged') )
我忘记了在哪里找到此功能,但在我的几个项目中都可以正常使用。 它也使事情变得更容易阅读和编辑。
if ( ! function_exists( 'my_pagination' ) ) :
function my_pagination($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,
'prev_text' => __('<'),
'next_text' => __('>'),
'type' => 'plain',
) );
}
endif;
我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.