1

I'm doing a WordPress theme, and I get stuck on one thing. As you know, the post-format in WordPress has different types of formats, I did all the types except the gallery slideshow. What I need, for example I had create one new post, and added gallery with pictures to this post, then I chose a gallery in post format. The problem, the gallery shows me all the images included in WordPress but I want to show only the post images.

Code:

    if ( ! function_exists(    'flexi_gallery_slideshow' ) ) :
   /**
   * Display an optional post images.   slideshow
   *
   */ 
  function flexi_gallery_slideshow( ){

  echo '<ul class="bxslider" >';
  $args = array(
  'post_parent' =>$post->ID,
  'post_type' => 'attachment',
  'orderby' => 'menu_order', // you can   also sort images by date or be name
  'order' => 'ASC',
  'numberposts' => 3, // number of. images (slides)
  'post_mime_type' => 'image'
  );
   if ( $images = get_children( $args )  ) {
   foreach( $images as $image ) {
            echo '<li>';
            echo wp_get_attachment_image($image->ID, array('640', '400')        );

            echo '</li>';
        }
  }

    echo '</ul>';

 }
 endif;
  • Where and how do you call the function? Had you checked that $post holds sane value at that point? – Rarst May 26 '16 at 17:40
  • 1
    i create new content-gallery file and call the function there, and i create a post in gallery format, and i chose some pictures as galleries, the out of slider is shown the pictures inside the media not shown the pictures which i loaded, shown all the pictures in media – ahmad araj May 26 '16 at 20:00
1

i had sort out this with function get_post_gallery

find the answer

if ( ! function_exists( 'flexi_gallery_slideshow' ) ) :
/**
* Display an optional post read more link
*
*/ 
function flexi_gallery_slideshow( ) {
echo '<ul class="bxslider">';
if ( get_post_gallery() ) :
        $gallery = get_post_gallery( get_the_ID(), false );

        /* Loop through all the image and output them one by one */
        foreach( $gallery['src'] as $src ) : ?>
          <li> <img src="<?php echo $src; ?>" class="gallery-slider" alt="Gallery image" /> </li>
          <?php
        endforeach;
    endif;
echo '</ul>'  ;     
}
endif;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.