NextGen插件-显示库图像计数



我正在为一个网站使用NextGen图库WordPress插件。在gallery.php模板中,我想检索循环中显示的每个库的图像数量。我想不出一种方法来获取数据并将其打印在gallery.php 中调用的每个库的缩略图下

这是我想插入画廊图像计数并打印的地方:

<a rel="prettyPhoto" href="<?php echo $image->imageURL ?>" 
<?php $image->thumbcode ?>><span>view</span></a> <?php echo $total_images; ?> pictures

有人有什么建议吗?

谢谢,Ian

我用这个小技巧从粘贴在帖子中的短代码([ngallery=1])中获取我的图库id

<?php
$id = get_the_ID();//Get the id of the specific post (inside the loop)
$string = get_the_content();//You get the whole post content where in the end of it lies your shortcode (for example [nggallery=1])
if(preg_match_all('/=(.*?)]/s',$string,$match)) {            
$finalstring=$match[1][0];
}// get the id only (gets all chars after '=' and before ']')
global $wpdb;
$total_attachments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid=$finalstring" ); // Voila!
?>

希望我的解决方案能为您服务。

这是你需要计算图像的代码:

$global $wpdb;
$images    = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures") );
$galleries = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggallery") );
$albums    = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggalbum") );

答案是你做不到。您可以计算$images变量中的键,但它会返回错误的数字。你可以检索所有图像的总数,或者所有无用的图库。你甚至可以在循环数组时使用计数器来计算图库中的图像数量,但你仍然会得到错误的数字。默认情况下,您可以尝试在此处使用全局变量tt:images->total,这些变量为空且未定义,甚至不存在于$images或$current对象中。

代码显示一个("第3张图片,共7张)"类型的显示。如果您在imagebrowser.php模板中使用它,它就会起作用。如果您在gallery-carousel.php模板中粘贴完全相同的代码。它不会起作用。现在,您可能认为切换到$current->total会起作用,因为在使用gallery_coursel时,它莫名其妙地会对其余变量起作用,但事实并非如此答案是你必须直接从数据库中提取信息

<?php _e('Picture', 'nggallery') ?> <?php echo $image->number ?> <?php _e('of',      'nggallery')?> <?php echo $image->total ?>

这是一个阴险的插件。

如果你不能计算图库上的图像,你可以计算html块上的标签。

在我的主题中,我从一个自定义字段中获取库ID,并在模板中回显库。所以,它是这样的:

<?php
$myGalleryId = 1; // example
$displayImages = 0; // the number of images you want to display from gallery. 0 = all images 
$newnggShortcodes = new NextGEN_Shortcodes;
$htmlGallery = str_get_html($newnggShortcodes->show_gallery( array("id"=>$myGalleryId,"images"=>$displayImages,"template"=>"popular") ));
$countImg = count($htmlGallery->find('img')); // number of total <img> tags inside the gallery
$str = $htmlGallery;
?>
<!-- now the html -->
<div id="myGallery">
<?php echo $str; ?>
</div>
<span>Total images: <?php echo $countImg; ?></span>

希望能有所帮助。

最新更新