【发布时间】:2017-03-14 21:40:34
【问题描述】:
对于高级自定义字段转发器的帮助,我将不胜感激。问题是我正在使用插件构建一个画廊,但我需要在页面末尾进行分页。我正在显示分页链接,但是单击时它们似乎不起作用。它与页面的网址有关吗 - 它没有在网址中显示页码。这是我的代码:
<?php
/*
* Paginate Advanced Custom Field repeater
*/
if (get_query_var('paged')) {
$page = get_query_var('paged');
} else {
$page = 1;
}
// Variables
$row = 0;
$images_per_page = 2; // How many images to display on each page
$images = get_field('thumbnail_image_repeater');
$total = count($images);
$pages = ceil($total / $images_per_page);
$min = (($page * $images_per_page) - $images_per_page) + 1;
$max = ($min + $images_per_page) - 1;
?>
<?php
if (have_rows('thumbnail_image_repeater')):
?>
<?php
while (have_rows('thumbnail_image_repeater')):
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
$image = get_sub_field('thumbnail_image');
$thumbnail_name = get_sub_field('thumbnail_name');
?>
<li class="col-xs-6 col-sm-4 col-md-3" data-responsive="<?php
echo $image['url'];
?>" data-src="<?php
echo $image['url'];
?>" data-sub-html="<h4><?php
echo $thumbnail_name;
?></h4><p><?php
echo $thumbnail_name;
?></p>" data-pinterest-text="Pin it1" data-tweet-text="share on twitter 1">
<a href="">
<img class="img-responsive" src="<?php
echo $image['url'];
?>" alt="Thumb-1" />
</a>
</li>
<?php
endwhile;
// Pagination
echo paginate_links(array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?page=%#%',
'current' => $page,
'total' => $pages,
'prev_text' => __('<<<'),
'next_text' => __('>>>')
));
?>
<?php
endif;
?>
【问题讨论】:
-
尝试将格式更改为 'paged=' 而不是 'page='。
-
试过了,但没有用。还有别的问题。我想一些带有 url 的东西,wordpress 没有在第二页添加 /2/,在第三页添加 /3/ 等等。
-
您是否尝试过添加 page_url/page/2 而不仅仅是 page_url/2?如果这没有帮助,那么我可以提出一个解决方案来注册您自己的 url 重写并将其应用于您的分页。
标签: wordpress pagination advanced-custom-fields image-gallery