• Hey,

    Hope someone can help with this. What I want is to display Post Thumbnails from a specific category in the flexslider.

    I’m using the following code so far which gets all irfomation from a specific category posts, but the thumbnails does not appear as a slide.

    <?php
    function add_flexslider() { // display attachment images as a flexslider gallery
    
    $attachments = get_children(array(
    		'numberposts' => 2,
    		'post_status'=>"publish",
    		'post_type'=>"post",
    		'category_name' =>   'Destaque',      // category slug
    		)
    		);
    
    	if ($attachments) { // see if there are images attached to posting
    
    		echo '<div class="flexslider">';
    		echo '<ul class="slides">';
    
    		foreach ( $attachments as $attachment_id => $attachment ) { // create the list items for images with captions
    
    			echo '<li>';
    			echo wp_get_attachment_image_src( get_post_thumbnail_id($attachment->ID), 'full' );
    			echo '<p>';
    			echo get_post_field('post_excerpt', $attachment->ID);
    			echo '</p>';
    			echo '</li>';
    
    		}
    
    		echo '</ul>';
    		echo '</div>';
    
    	} // end see if images
    
    }
    //
    ?>
Viewing 1 replies (of 1 total)
  • Hello drigo20,

    You have used below code which Returns an array (url, width, height, is_intermediate), or false, if no image is available.

    echo wp_get_attachment_image_src( get_post_thumbnail_id($attachment->ID), 'full' );

    You need to use like this:

    $image_attributes = wp_get_attachment_image_src( $attachment->ID );
    if ( $image_attributes ) : ?>
        <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" />
    <?php endif; ?>

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Get Post Thumbnails from X category to display in flexslider’ is closed to new replies.