高级自定义字段转发器上的寻呼已停止工作



不确定这是因为升级到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

你可以在那里查看一些解决方案。这似乎是查询var"的问题;页面";哪个是在WordPress核心中保留的,因为它通常使用?p和?页面重定向到某个页面。

所以你可能会用别的东西。

如果其他人仍在为此而挣扎,以下是在大多数解决方案都无法正常工作后我如何解决的:

$page = 1; //right after get_header();
global $wp_query;
$wp_query->is_paged = 1;
if ( isset( $_GET['chapter'] ) ) {
$wp_query->query_vars['paged'] = $_GET['chapter'];    
}
if( get_query_var('paged') ) {
$page = get_query_var( 'paged' );
} 

对于分页链接,我使用了这个

echo paginate_links( array(
'base' => get_permalink() . '?chapter=%#%',
'current' => $page,
'total' => $pages
) );

不是最好的解决方案,但对我有效。

最新更新