我重写了代码库,并在分页时停止。如何获得最大页数?目前我无法定义它,并对数字5进行了测试。
(Here "for ($ i = 1; $ i <= 5; $ i ++)" here "if ($ paged <5))."
如何在分页中设置work offset参数?现在,当我放置参数offset时,分页将无法正常工作。我需要发布
16 图片
post_per_page
was equal to 4. 我还没有为我的具体案例找到解决方案。也许可以用什么东西来代替?这是我的完整代码
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;
}