offset and max_num_pages in pagination gallery
I rewrote the code galleries and stopped at the pagination. How can I get the maximum number of pages? at the moment I can not define it, and put a test for the number 5.
(Here "for ($ i = 1; $ i = 5; $ i ++)" here "if ($ paged 5))."
And how to make that work offset parameter in pagination? Now when I put the parameter offset, pagination will not work correctly. I need to post 16 pictures post_per_page
was equal to 4. I have not found a solution for my specific case. Maybe it can be replaced with something? Here is my complete code in funсtions.php
remove_shortcode("gallery");
add_shortcode("gallery","my_gallery");
function my_gallery($atts){
$img_id = explode(',', $atts['ids']);
if(!$img_id[0]) {
return 'div class="no-img-gallery"No images/div';
}
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$pictures = get_posts( array(
'posts_per_page' = 4,
'post__in' = $img_id,
'paged' = $paged,
'post_type' = 'attachment',
) );
$html = 'div class="gallery-my"';
foreach ($pictures as $item){
$img_desc = $item-post_content;
$img_caption = $item-post_excerpt;
$img_title = $item-post_title;
$img_thumb = wp_get_attachment_image_src($item-ID);
$img_full = wp_get_attachment_image_src($item-ID,medium);
$html .="
div class='item-gallery'
a href='{$img_full[0]}'
img src='{$img_thumb[0]}' width='{$img_thumb[1]}' height='{$img_thumb[2]}' alt='{$img_title}'
div class='desc-wrap'
strong class='title-img'{$img_title}/strong
span class='desc-img'{$img_desc}/span
/div
/a
/div";
}
$html .= "/div";
//Pagination
$html .= "div class='pagination-gallery'";
if ($paged 1) {
$html .="span class='prev-cust'
a href='?paged=".($paged-1)."'/a
/span/div";
}
for($i=1;$i=5;$i++){
$html .="span class='num-pag'
a href='?paged=".$i."'";
if($paged==$i){
$usl='class="selected"';
}
else{
$usl='';
}
$html .=$usl."".$i."/a/span";
}
if ($paged 5) {
$html .="span class='prev-cust'
a href='?paged=".($paged+1)."'/a
/span/div";
}
$html .= "/div";
return $html;
}