wordpress - 高级自定义字段中继器上的分页停止工作
问题描述
不确定这是否是因为升级到 PHP 7.2 或最新的 WordPress 版本,但以下代码用于允许我为转发器值添加分页。现在似乎发生的是页面只是重新加载页面。分页链接显示为/example/2/
,这用于加载页面,但现在它只是重新加载example
。
有任何想法吗?
<?php
/*
* Paginatation on Advanced Custom Fields Repeater
*/
if ( get_query_var('paged') ) {
$page = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$page = get_query_var('page');
} else {
$page = 1;
}
// Variables
$row = 0;
$images_per_page = 10; // How many images to display on each page
$images = get_field( 'image_gallery' );
$total = count( $images );
$pages = ceil( $total / $images_per_page );
$min = ( ( $page * $images_per_page ) - $images_per_page ) + 1;
$max = ( $min + $images_per_page ) - 1;
// ACF Loop
if( have_rows( 'image_gallery' ) ) : ?>
<?php while( have_rows( 'image_gallery' ) ): the_row();
$row++;
// Ignore this image if $row is lower than $min
if($row < $min) { continue; }
// Stop loop completely if $row is higher than $max
if($row > $max) { break; } ?>
<?php $img_obj = get_sub_field( 'image' ); ?>
<a href="<?php echo $img_obj['sizes']['large']; ?>">
<img src ="<?php echo $img_obj['sizes']['thumbnail']; ?>" alt= "Your ALT Tag" />
</a>
<?php endwhile;
// Pagination
echo paginate_links( array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?paged=%#%',
'current' => $page,
'total' => $pages
) );
?>
<?php else: ?>
<p>No images found</p>
<?php endif; ?>
解决方案
5.5 之后有一个错误跟踪器: https ://core.trac.wordpress.org/ticket/50976#comment:7
您可以在那里查看一些解决方案。这似乎是 WordPress 核心中保留的查询变量“page”的问题,因为它通常使用 ?p 和 ?page 重定向到某个页面。
所以你可能会使用其他东西。
推荐阅读
- flutter - Flutter:flutter_swiper 包控制幻灯片之间的空间
- php - 不知道有多少参数时的准备语句
- python - 使用 SSH 在远程计算机上打开浏览器
- javascript - 选择下拉菜单项时自动从我的数据库中填写 textarea 字段
- javascript - 将字符串与正则表达式匹配时出错
- java - 用另一个类的实例字段影响一个类的实例字段
- javascript - Laravel如何根据查询按天渲染成融合图表
- c# - 在 IOptions .NET Core 1.1 及更高版本的延迟验证之上的单元测试自定义急切验证
- java - Apache Storm 2.1.0 本地 DRPC 不返回任何响应,尽管最后一个螺栓很好地向收集器发出了一个元组
- android - 在 Android 中使用自定义字体时,EditText 中的首字母输入不完全可见