2

サイトに 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

誰にもヒントはありますか?

ありがとう、イアン

4

4 に答える 4

1

この小さなハックを使用して、投稿内に貼り付けたショートコード ([nggallery=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!
?>
于 2014-01-21T19:09:37.280 に答える
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") );
于 2012-11-17T04:58:49.560 に答える
0

答えは、できません。$images 変数でキーを数えることはできますが、間違った数が返されます。すべての画像の総数、または役に立たないすべてのギャラリーを取得できます。ギャラリー内の画像の数をカウントするために配列を循環するときにカウンターを使用することもできますが、それでも間違った数が得られます。デフォルトでグローバル変数 images->total を使用してみることができます。これは空で未定義であり、$images または $current オブジェクトにも存在しません。

このコードは、("Picture 3 of 7)" タイプのディスプレイを表示します。imagebrowser.php テンプレートで使用すると、機能します。これとまったく同じコードを gallery-carousel.php テンプレートに貼り付けます。効果がないでしょう。gallery_carousel を使用している場合、$current->total に切り替えるとうまくいくと思われるかもしれませんが、そうではありません。答えは、データベースから直接情報を取得する必要があるということです。

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

それは不吉な、不吉なプラグインです。

于 2013-01-01T03:23:26.627 に答える
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>

それが役に立てば幸い。

于 2013-03-14T18:58:45.590 に答える