Без долгих рассказов опишу как создать разбивку страницы с ACF галереей.
Вот код с первоисточника. Все вставляется в шаблон страницы php кодом.
//Setup pagination variables
$gallery = get_field('gallery'); // Get our gallery
$images = array(); // Set images array for current page
$items_per_page = 12; // How many items we should display on each page
$total_items = count($gallery); // How many items we have in total
$total_pages = ceil($total_items / $items_per_page); // How many pages we have in total
//Get current page
if ( get_query_var( 'paged' ) ) {
$current_page = get_query_var( 'paged' );
}elseif ( get_query_var( 'page' ) ) {
//this is just in case some odd rewrite, but paged should work instead of page here
$current_page = get_query_var( 'page' );
}else{
$current_page = 1;
}
$starting_point = (($current_page-1)*$items_per_page); // Get starting point for current page
// Get elements for current page
if($gallery){
$images = array_slice($gallery,$starting_point,$items_per_page);
}
if(!empty($images)){
//your gallery loop here
}
// And our pagination
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
'before_page_number' => '<span class="screen-reader-text">'.__('Page ','textdomain').' </span>'
));
Если нужны нужна кнопка “загрузить еще” то вместо последнего абзаца ставим это:
if($total_pages>1 && $current_page<$total_pages){
echo '<a href="'.get_permalink().'page/'.($current_page+1).'/">'.__('Load more','textdomain').'</a>';
}
Если нужны кнопки вперед и назад тогда это:
// Set previous page
if($total_pages>1 && $current_page<=$total_pages && $current_page!=1){
echo '<a href="'.get_permalink().(($current_page-1)!=1 ? 'page/'.($current_page-1).'/' : '').'">'.__('Previous','textdomain').'</a>';
}
// Set next page
if($total_pages>1 && $current_page<$total_pages && $current_page!=$total_pages){
echo '<a href="'.get_permalink().'page/'.($current_page+1).'/">'.__('Next','textdomain').'</a>';
}
вот код который уже работал! можно сравнить с исходником.
<?php
$gallery = get_field('field_59f2a1869ef2b');
$images = array();
$items_per_page = 4;
$total_items = count($gallery);
$size = 'full';
$total_pages = ceil($total_items / $items_per_page);
if(get_query_var('paged')){
$current_page = get_query_var('paged');
}
elseif (get_query_var('page')) {
$current_page = get_query_var('page');
}
else{
$current_page = 1;
}
$starting_point = (($current_page-1)*$items_per_page);
if($gallery){
$images = array_slice($gallery,$starting_point,$items_per_page);
}
if(!empty($images)){
foreach( $images as $image ):
echo wp_get_attachment_image( $image['ID'], $size );
endforeach;
}
$big = 999999999;
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
));
?>