php - 分页循环仅显示两页
问题描述
我是 wordpress 的最后一名大三学生,想**pagination**
用 wp_query 创建,但我只得到 2 页,但是我有 8 个帖子,每页显示 2 个——我在不同的网站上搜索了很多,但没有找到答案
<?php //GET POSTS
$paged = get_query_var( 'paged' );
$arr=array(
'author' =>the_author_meta('id'),
'posts_per_page' => 2,
'paged' =>$paged,
);
$special_query= new WP_Query($arr);//SPECIAL QUERY
if($special_query->have_posts()){//check if there is posts or no
while($special_query->have_posts()){
$special_query-> the_post();
/*content*/
?>
解决方案
尝试这个
$query = array(
'post_type' => 'post',
'posts_per_page' => 2,
'author'=>the_author_meta('id'),
'ignore_sticky_posts' => true,
'paged' => get_query_var('paged') ? get_query_var('paged') : 1
);
$loop = new WP_Query($query);
if( $loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();
//postcode
endwhile;
endif;
$big = 9999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged') ),
'total' => $loop->max_num_pages
) );
推荐阅读
- python - 我发生了错误异常:TypeError 元组索引必须是整数或切片,而不是 str(Open CV)?
- javascript - 无法推送嵌套数组中子项的数据子项
- vba - 将表存储在内存中(ArrayList?)
- javascript - Reducer 没有将数据保存到 React Context API 中的状态
- node.js - Gulp 在正常工作一年多后停止工作,现在在命令行中出现“无法识别术语 'gulp'”错误
- python - 从 Python 中的列表中获取对象?
- javascript - 动态表单创建和添加输入字段
- calendar - google calendar api service.calendars().clear(calendarId=calenderID).execute() 返回无效值
- r - Mac上的R RSelenium rsDriver chrome浏览器错误
- java - 将 SeekBar 添加到 SettingsActivity