2010-03-20 12 views
5

Slayt gösterisi türünde bir gönderime eklenen görüntüleri tek tek göstermek için resim eki sayfasını kullanıyorum. Resim ve kelime "Resim 3/15" kelimelerini görebilmeniz için, herhangi bir ek sayfada görüntülenen belirli görüntünün sayısını ve ana gönderiye eklenen toplam görüntü sayısını görüntüleyebilmek istiyorum Örneğin. Hala geçerli görüntünün sayısını göstermek için nasıl bilemiyorumResim eki sayfasındaki bir gönderiye eklenen görüntülerin sayısını nasıl gösteririm?

<?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; 
?> 

:

Güncelleme ... Bu kodu kullanarak göstermek için toplam sayısını elde edebildi.
Herhangi bir öneriniz var mı?

Güncelleme 2 ...

Greenie cevabı neredeyse san bakalım ama bir kerede tüm sayılar çıktısı oluyor:

"Resim 1 8Image 2 8Image 3 arasında 8Image 4 8Image 6 8Image 5 İşte

kullandığım kodu 8" 8Image 8 nin 8Image 7:

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++; 
} 

Neler oluyor?

Güncelleştirme 3 - CEVAP!

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}"; 

cevap

1

Bu çalışır:

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}"; 
0

yukarıdaki koda böyle bir şey ekleyin:

$currentImage = 1; 
foreach ($attachments as $attachment) { 
    // output your image here 
    echo "Image ". $currentImage . " of ". $count; 
    $currentImage++; 
} 
+0

Teşekkür resimlerinizin sırasını değiştirebilir. Bu beni neredeyse oradan aldı. Yukarıdaki soruyu güncel sorunla güncelledim. – mattz

0

Bir eklentiyle arıyorsanız resim galerisi yönetmek, sen attachments kullanabilirsiniz eklenti,

http://wordpress.org/plugins/attachments/

Galeriyi ayrı tutar ve resim galerisi kısa kodlarını yazılan içeriğe yerleştirmez, böylece post/page/custom post öğenizde görüntü üzerinde tam bekletme sağlar. Ayrıca, sadece sürükle-bırak burada

galeri görüntüleri almak için nasıl bir örnek kod tarafından cevap için

<?php $attachments = new Attachments('attachments'); /* pass the instance name */ ?> 
<?php if($attachments->exist()) : ?> 
    <h3>Attachments</h3> 
    <p>Total Attachments: <?php echo $attachments->total(); ?></p> 
    <ul> 
    <?php while($attachments->get()) : ?> 
     <li> 
     ID: <?php echo $attachments->id(); ?><br /> 
     Type: <?php echo $attachments->type(); ?><br /> 
     Subtype: <?php echo $attachments->subtype(); ?><br /> 
     URL: <?php echo $attachments->url(); ?><br /> 
     Image: <?php echo $attachments->image('thumbnail'); ?><br /> 
     Source: <?php echo $attachments->src('full'); ?><br /> 
     Size: <?php echo $attachments->filesize(); ?><br /> 
     Title Field: <?php echo $attachments->field('title'); ?><br /> 
     Caption Field: <?php echo $attachments->field('caption'); ?> 
     </li> 
    <?php endwhile; ?> 
    </ul> 
<?php endif; ?> 
İlgili konular