2012-11-17 47 views
2

我現在用的是NextGen的畫廊WordPress插件的網站。在我的gallery.php模板中,我想檢索循環中顯示的每個圖庫的圖像數量。我不能想出一個辦法來獲取數據和每家畫廊的縮略圖這就是所謂的gallery.phpNextGen的插件 - 顯示圖庫計數

這裏下打印出來的,我想插入庫圖像數量和打印:

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

任何人有任何提示?

感謝, 伊恩

+0

你的意思是你想連接到每個崗位的所有圖像的畫廊? – loQ

+0

我只是想讓圖片附加到每個圖庫並在每個圖庫縮略圖下顯示計數。 –

+0

一個畫廊的圖像來自一個帖子吧?所以你必須得到一個帖子附加的全部圖像?我對嗎? – loQ

回答

0

希望我的解決方案可以爲你工作。

這是你需要計算圖像的代碼:

$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")); 
+0

我試過這個,但是我無法獲取圖片*每個*圖庫。它僅打印所有畫廊中的圖像總數。我怎樣才能打印出每個畫廊的圖像數量? '<?php global $ wpdb; $ images = intval($ wpdb-> get_var(「SELECT COUNT(*)FROM $ wpdb-> nggpictures」)); ?> thumbcode ?>>view<?php echo $ images; ?>圖片' –

+0

您必須根據您的要求調整此代碼。 –

0

答案是你不能。 您可以計算$ images變量中的鍵,但會返回錯誤的數字。 您可以檢索所有圖像的總數,或無用的所有畫廊。 您甚至可以在循環訪問陣列時使用計數器來嘗試統計圖庫中的圖像數量,但仍會得到錯誤的編號。 你可以嘗試用默認tthere使用全局變量:圖像 - >總,這是空的,不確定的,甚至不在$圖像或$當前對象存在。

代碼顯示( 「圖片7的3)」 類型的顯示器。如果你在imagebrowser.php模板中使用它,它可以工作。如果您將相同的代碼粘貼到gallery-carousel.php模板中。不起作用。現在你可能會認爲切換到$ current-> total會起作用,因爲它在使用gallery_carousel時對其餘變量無法解釋,但是不,它不會。 答案是你必須直接從數據庫中提取信息。

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

這是一個險惡險惡的插件。

0

如果你不能指望一個畫廊的圖片,你可以指望的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> 

希望它有幫助。

1

我用這個小黑客從我我門柱內側粘貼的簡碼得到我的畫廊ID([nggallery = 1])

<?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! 
?> 
相關問題