• 22-09-2012, 01:18:51
    #1
    Yazıya eklenen tüm resimleri çeken bir fonkisyon buldum. Ancak php bilgim yeterli olmadığından işin içinden çıkamadım. Şöyle ki bulduğum fonksiyonu döngü içerisine aldığımda döngü çalışmıyor. Çıktı olarak sadece 1 tane post görünüyor.

    Resimleri çeken fonksiyon:
                        	<?php while ( have_posts() ) : the_post();    
                        			 $args = array(
                        			   'post_type' => 'attachment',
                        			   'post_status' => null,
                        			   'post_parent' => $post->ID
                        			  );
    
                        			  $attachments = get_posts( $args );
                         			    if ( $attachments ) {
                        			        foreach ( $attachments as $attachment ) {
                        					   $full_image = wp_get_attachment_image_src( $attachment->ID, 'full', false, false );
                        					   list ( $full_src, $full_width, $full_height ) = $full_image;
                        					   echo '<li><a href="'.$full_src.'" rel="shadowbox[images]">';
                          			           echo wp_get_attachment_image( $attachment->ID, 'mini' );
                        					   echo '</a></li>';
                          			        }
                          			   }
                        			 endwhile; ?>
    Döngü fonksiyonu ile birlikte böyle kullandım:
    <?php $dongu = new WP_Query("showposts=5&cat=1"); while($dongu->have_posts()) : $dongu->the_post();?>
    
    
    <?php while ( have_posts() ) : the_post();    
                        			 $args = array(
                        			   'post_type' => 'attachment',
                        			   'post_status' => null,
                        			   'post_parent' => $post->ID
                        			  );
    
                        			  $attachments = get_posts( $args );
                         			    if ( $attachments ) {
                        			        foreach ( $attachments as $attachment ) {
                        					   $full_image = wp_get_attachment_image_src( $attachment->ID, 'full', false, false );
                        					   list ( $full_src, $full_width, $full_height ) = $full_image;
                        					   echo '<li><a href="'.$full_src.'" rel="shadowbox[images]">';
                          			           echo wp_get_attachment_image( $attachment->ID, 'mini' );
                        					   echo '</a></li>';
                          			        }
                          			   }
                        			 endwhile; ?>
    
    
    <?php endwhile; ?>
    Bu döngünün çalışması için ne gibi düzenleme yapmam gerekiyor?
  • 22-09-2012, 10:54:42
    #2
    bnu sanırım tekil yazıda kullanmak istiyorsunuz.
    zaten tekil yazıda while have post döngüsü 1 kez döner.

    ayrıca bulduğunuz kod hatalı.

    şunu ekleyin single.php ye.herhangi bir yerine.

    <?php
    $args = array(
        'post_type' => 'attachment',
        'numberposts' => -1, // görüntülenecek yazı sayısı (-1 = tümü)
        'post_status' => null, 
        'post_parent' => $post->ID // geçerli yazı
        ); 
    $resler = get_posts($args);
    if ($resler) {
        foreach ($resler as $res) {
    	$resim_link = wp_get_attachment_image_src( $res->ID, 'mini' , false);
    	$resim = wp_get_attachment_image( $res->ID); 
           echo '<li><a href="'.$resim_link[0].'" rel="shadowbox[images]">'.$resim.'</a></li>';
        }
    } else {
        echo 'Resim bulunamadı.';
    }
    ?>
  • 22-09-2012, 14:42:50
    #3
    Cevabın için çok sağol hocam. Bir de tekil yazıda değil de belli bir kategorideki son 5 yazının resimlerini çekmek istiyorum bu fonksiyonla. Acaba o mümkün mü?