如何解决在高级自定义字段中继器上的分页停止工作
不知道这是否是自升级到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核心中保留的查询var“ page”似乎是一个问题,因为它通常使用?p和?page重定向到特定页面。
所以您可能会使用其他东西。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。