画像添付ページを使用して、投稿に添付された画像を 1 つずつ、スライドショーのような効果で表示します。親投稿に添付された画像の総数と、特定の添付ページに表示されている特定の画像の数を表示できるようにして、たとえば、画像と「15 の画像 3」という言葉を表示できるようにしたいと考えています。 .
更新... このコードを使用して表示する合計数を取得できました:
<?php
global $post;
$attachments = get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
$count = count( $attachments );
echo $count;
?>
現在の画像の番号を表示する方法がまだわかりません。
誰にも提案はありますか?
更新 2...
Greenie's answer は私をほぼそこに導きましたが、一度にすべての数値を出力しています:
「画像 1/8 画像 2/8 画像 3/8 画像 4/8 画像 5/8 画像 6/8 画像 7/8 画像 8/8」
使用したコードは次のとおりです。
global $post;
$attachments = get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
$count = count( $attachments );
$currentImage = 1;
foreach ($attachments as $attachment) {
// output your image here
echo "Image ". $currentImage . " of ". $count;
$currentImage++;
}
何がうまくいかないのですか?
アップデート 3 - 答え!
global $post;
$attachments = get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
$count = count( $attachments );
$specific = array();
$i = 1;
foreach ( $attachments as $attachment ) {
$specific[$attachment->ID] = $i;
++$i;
}
echo "Image {$specific[$post->ID]} of {$count}";