Ich verwende die Bildanhangsseite, um Bilder, die an einen Post angehängt sind, nacheinander in einer Art Diashow anzuzeigen. Ich möchte in der Lage sein, die Gesamtanzahl der an den Elternpost angehängten Bilder und die Nummer des jeweiligen Bilds anzuzeigen, das auf einer bestimmten Anhangsseite angezeigt wird, sodass Sie das Bild und die Wörter "Image 3 of 15" sehen können beispielsweise.Wie kann ich die Anzahl der Bilder anzeigen, die einem Beitrag auf der Bildanhangsseite angehängt sind?
Update ... Ich konnte die Gesamtzahl bekommen diesen Code zu verwenden:
<?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;
?>
Ich kann immer noch nicht herausfinden, wie die Nummer des aktuellen Bildes zu zeigen.
Hat jemand irgendwelche Vorschläge?
Update 2 ...
Antwort des Grünschnabel- mich bekam fast da, aber es auf einmal alle Zahlen ist die Ausgabe:
„Bild 1 von 8Image 2 von 8Image 3 von 8Image 4 von 8Image 5 von 8Image 6 von 8Image 7 von 8Image 8 von 8"
Hier ist der Code I verwendet:
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++;
}
Was läuft falsch?
Update 3 - DIE ANTWORT!
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}";
Vielen Dank für die Antwort. Das hat mich fast dahin gebracht. Ich habe meine Frage oben mit dem aktuellen Problem aktualisiert. – mattz