Это приближается к тому, что мне нужно. Он разбивает 5 результатов из $ files (get_post_meta) и создает страницы, но изображения представляют собой одинаковые изображения на всех страницах. Я вне пределов своего мозга.CMB2 Тип файла типа paginate results (использует get_post_meta)
function gallery_loop() {
if(get_query_var('page')) {
$page = get_query_var('page');
} else {
$page = 1;
}
$img_size = 'portfolio-catalog';
$files = get_post_meta(get_the_ID(), '_cmb_gallery_images', true);
$limit = 5;
$total = count($files);
$pages = ceil($total/$limit);
$curr_page = isset($_GET['page']);
$offset = ($curr_page - 1) * $limit;
$items_array = array_chunk((array) $files, $limit, true);
$files_array = array_slice($items_array, $offset, true); // this is showing the same 5 items on all the pages
foreach ($files_array as $files) {
echo '<div style="border:1px solid red;">'; //BEGIN "page" so I can see if they are splitting correctly
foreach ($files as $attachment_id => $attachment_url) {
$page=1;
echo '<div class="file-list-image">';
echo wp_get_attachment_image($attachment_id, $img_size);
echo '</div>';
$page++;
} // end $files as $attachment_id => $attachment_url
echo '</div>'; //END "page" so I can see if they are splitting correctly
} // end foreach $files_array as $files
//the correct amount of pages are showing up but the items are all the same
echo paginate_links(array(
'base' => get_permalink() . '%#%' . '/',
'format' => '?page=%#%',
'current' => $page,
'total' => $pages
));
}
// end function
разделить массив на куски с помощью 'array_chunk' и затем обрабатывать каждый кусок в качестве разбитым на страницы набора файлов возможно – RamRaider