Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何设置库的分页?_Php_Wordpress_Pagination - Fatal编程技术网

Php 如何设置库的分页?

Php 如何设置库的分页?,php,wordpress,pagination,Php,Wordpress,Pagination,我取代了他们自己的标准WordPress图库。我无法绑定到图库的页码。每页发布不起作用 remove_shortcode("gallery"); add_shortcode("gallery","my_gallery"); function my_gallery($atts){ $img_id = explode(',', $atts['ids']); if(!$img_id[0]) { return '<div

我取代了他们自己的标准WordPress图库。我无法绑定到图库的页码。每页发布不起作用

  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>';
        }

        $html = '<div class="gallery-my">';
        foreach ($img_id as $item){
            $img_data = get_posts(array(
                'posts_per_page' => '8',
                'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
                'p' => $item,
                'post_type' => 'attachment'
            ));

            $img_desc = $img_data[0]->post_content;
            $img_caption = $img_data[0]->post_excerpt;
            $img_title = $img_data[0]->post_title;
            $img_thumb = wp_get_attachment_image_src($item);
            $img_full = wp_get_attachment_image_src($item,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>";


        return $html;
    }
remove_shortcode(“库”);
添加快捷码(“图库”、“我的图库”);
功能我的画廊($atts){
$img_id=explode(',',$atts['id']);
如果(!$img\u id[0]){
返回“无图像”;
}
$html='';
foreach($img\u id作为$item){
$img\u data=get\u posts(数组(
“每页帖子数”=>“8”,
“paged'=>(获取查询变量('paged')?获取查询变量('paged'):1),
“p”=>$item,
“post_类型”=>“附件”
));
$img_desc=$img_数据[0]->发布内容;
$img_caption=$img_data[0]->post_摘录;
$img_title=$img_data[0]->post_title;
$img\u thumb=wp\u get\u attachment\u image\u src($item);
$img\u full=wp\u get\u attachment\u image\u src($item,medium);
$html.=”
";
}
$html.=”;
返回$html;
}
告诉我要向代码中添加什么以使其工作。或者改变它

试试看

'posts_per_page' => 8,
8周围没有撇号