Obține Descrierea Imaginii
                            6 dec. 2013, 06:29:26
                        
                    
                            Vizualizări: 39.5K
                        
                    
                            
                            
                                Voturi: 19
                            
                        
                    Încerc să creez o postare împărțită în 2 coloane. Prima coloană din stânga va conține orice imagine din postare, iar a doua coloană din dreapta va conține the_content() (excluzând imaginile).
Până acum nu am probleme în a extrage toate imaginile. Totuși - nu reușesc să obțin caption-ul, titlul sau descrierea imaginii.
Iată codul meu:
<?php if ( $images = get_posts(array(
        'post_parent' => $post->ID,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby'        => 'title',
        'order'           => 'ASC',
        'post_mime_type' => 'image',
    )))
    {
        foreach( $images as $image ) {
            $attachmenturl = wp_get_attachment_url($image->ID);
            $attachmentimage = wp_get_attachment_image_src( $image->ID, full );
            $imageDescription = apply_filters( 'the_description' , $image->post_content );
            $imageTitle = apply_filters( 'the_title' , $image->post_title );
            $i++;
            if (!empty($imageTitle)) {
                echo '<div class="client-img-item ci-'.$count++.'"><img src="' . $attachmentimage[0] . '" alt="'.$imageTitle.'"  /> <div class="CAPS client-img-caption"><span class="red arrow-lrg">»</span> '.$imageDescription.'</div></div><div class="sml-dots"></div>';
} else { echo '<img src="' . $attachmentimage[0] . '" alt="" />' ; }
        }
    } else {
        echo 'Nu a fost găsită nicio imagine';
    }?>
                
                            
                                    Moishy
                                
                                
                                        324
                                    
                                
            Comentarii
        
        
                Toate răspunsurile la întrebare
                
                1
                
            
        
                
                
                1
                
                
                    
                    
                    
                    
                        
                        
                            
                                
                        
                    
                    
                        
                            
                                
                                    
                                
                                
                                    
                                        
                                        
                                
                            
                            
                                
                            
                            
                    
                
            
        function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
    'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
    'caption' => $attachment->post_excerpt,
    'description' => $attachment->post_content,
    'href' => get_permalink( $attachment->ID ),
    'src' => $attachment->guid,
    'title' => $attachment->post_title
);
}
După cum explică sporkme mai târziu în discuție, acest cod trebuie adăugat în fișierul functions.php și poate fi apelat folosind $attachment_meta = wp_get_attachment(id-ul_atasamentului);.
                                
                                        Dylan Hildenbrand
                                    
                                    
                                            583
                                        
                                    
                                
                                6 dec. 2013 19:02:05
                            
                        
            Comentarii
        
        provin din : //https://gist.github.com/hullen/5443218 ????
                            menardmam
                        
                            
                            21 nov. 2015 17:12:18
                        
                    
                    Întrebări similare
                
                
                                        2
                                    
                                    
                                        răspunsuri
                                    
                                
                                        1
                                    
                                    
                                        răspunsuri
                                    
                                
                                        6
                                    
                                    
                                        răspunsuri