php - Wordpress:页面分页?
问题描述
在 wordpress 站点中,我有一个循环,可以在页面上显示某个类别的帖子。我有一个分页代码。显示分页。但是,如果我转到第 2、3、4 页……显示的结果始终是第一页。有人看到错误吗?
谢谢你的帮助。我看不到错误。
我的代码:
<a class="xyz" href="<?php the_permalink(); ?>"></a>
<h3 class="entry-title"><?php the_title(); ?></h3>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
?>
<?php the_excerpt(); ?>
</div><!-- grid-item -->
<?php
endwhile;
$total_pages = $tk_specials_querie->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('page'));
$paginate_links = paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'show_all' => False,
//'end_size' => 1,
// 'mid_size' => $pagerange,
'prev_next' => True,
'type' => 'plain',
'end_size' => 1,
'mid_size' => 2,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
));
}
?>
<?php
else :
esc_html_e( 'Derzeit keine Beiträge!', 'text-domain' );
endif;
wp_reset_postdata();
?>
解决方案
好的,我现在做到了。如果有人想知道如何:
<div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 445, "gutter": 20 }'>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '50',
'paged' => $paged,
'order' => 'DESC',
'orderby' => 'date',
'cat' => '949',
) );
?>
<?php if ( $query->have_posts() ) : ?>
<!-- begin loop -->
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="grid-item">
<a class="xyz" href="<?php the_permalink(); ?>"></a>
<h3 class="entry-title"><?php the_title(); ?></h3>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
?>
</div><!-- grid-item -->
<?php endwhile; ?>
<!-- end loop -->
<div class="tk_pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( '<', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( '>', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
?>
</div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
推荐阅读
- python-3.x - numpy 导入错误 ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
- amazon-web-services - 云监视日志中的自定义网关响应消息
- javascript - 如何在 React Native 中使用 React.forwardRef()
- html - 如何使用 CSS 和 HTML 从右向左移动表格
- jquery - 如何使用范围设置jquery掩码
- html - Vue 警告客户端渲染的虚拟 DOM 树与服务器渲染的内容不匹配
- excel - 获取 excel 将整行粘贴到新工作表上的下一个可用位置,而不是覆盖已经存在的数据
- xml - Powershell 列表框项目到 XML 节点
- python - numpy matmul 是否并行化以及如何停止它?
- c++ - 检查加载的DLL是否为系统模块