gpt4 book ai didi

wordpress - 默认的 wordpress 画廊分页

转载 作者:行者123 更新时间:2023-12-02 04:31:07 26 4
gpt4 key购买 nike

我到处寻找一个插件,通过分页将包含 80 张照片的默认 WordPress 3.8.3 图库分成 4 页,每页 20 张照片。我已经在网上查找了 2 天,但一直找不到任何东西...有人知道插件吗?

谢谢

最佳答案

我不确定您是否设法解决了这个问题。我确实有解决方案。

这是我所做的:首先在 wordpress 后端的特定页面上创建图库。然后在我的 functions.php 文件中添加了以下代码:

add_filter('post_gallery', 'filter_gallery', 10, 2);
function filter_gallery($output, $attr)
{
global $post;



//GALLERY SETUP STARTS HERE----------------------------------------//
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby'])
unset($attr['orderby']);
}
//print_r($attr);
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr));

$id = intval($id);
if ('RAND' == $order) $orderby = 'none';

if (!empty($include)) {
$include = preg_replace('/[^0-9,]+/', '', $include);
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));

$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
}
if (empty($attachments)) return '';
//GALLERY SETUP END HERE------------------------------------------//





//PAGINATION SETUP START HERE-------------------------------------//
$current = (get_query_var('paged')) ? get_query_var( 'paged' ) : 1;
$per_page = 24;
//$offset = ($page-1) * $per_page;
$offset = ($current-1) * $per_page;
$big = 999999999; // need an unlikely integer


$total = sizeof($attachments);
$total_pages = round($total/$per_page);
if($total_pages < ($total/$per_page))
{ $total_pages = $total_pages+1;
}
//PAGINATION SETUP END HERE-------------------------------------//














//GALLERY OUTPUT START HERE---------------------------------------//
$output = "<div class=\"gallery-images\">\n";
$counter = 0;
$pos = 0;
foreach ($attachments as $id => $attachment)
{ $pos++;
//$img = wp_get_attachment_image_src($id, 'medium');
//$img = wp_get_attachment_image_src($id, 'thumbnail');
//$img = wp_get_attachment_image_src($id, 'full');

if(($counter < $per_page)&&($pos > $offset))
{ $counter++;
$largetitle = get_the_title($attachment->ID);
$largeimg = wp_get_attachment_image_src($id, 'large');
$img = wp_get_attachment_image_src($id, array(100,100));
$output .= " <a href=\"{$largeimg[0]}\" data-lightbox=\"example-set\" title=\"{$largetitle}\"><img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" /></a>\n";
}

}
$output .= "<div class=\"clear\"></div>\n";
$output .= "</div>\n";
//GALLERY OUTPUT ENDS HERE---------------------------------------//






//PAGINATION OUTPUT START HERE-------------------------------------//
$output .= paginate_links( array(
'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => $current,
'total' => $total_pages,
'prev_text' => __('&laquo;'),
'next_text' => __('&raquo;')
) );
//PAGINATION OUTPUT ENDS HERE-------------------------------------//





return $output;
}

希望对你有帮助

关于wordpress - 默认的 wordpress 画廊分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23093441/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com