1

I am customizing this theme . I am using get_the_gallery() function to get the gallery from the custom post . I am able to do so, but when the gallery is inserted between the shortcodes...

For eg:

[two-third]

[gallery ids="18,17,8,7,6"]

[/two-third]

then i am not able to get the gallery..I am using the following code

<?php                  
    if ( get_post_gallery() ):     
       $gallery = get_post_gallery( $post, false );
       $w3_ids = explode( ",", $gallery['ids'] );               
?>                 

<?php  
    $gallery_count=1;
    foreach( $w3_ids AS $w3_id ): 
        $src = wp_get_attachment_image_src($w3_id,'full'); 
?>  
    <div class="item <?php if($gallery_count==1)echo "active"; ?>">
       <img src="<?php echo $src[0]; ?>" alt="" />
    </div>
<?php 
    $gallery_count++;
    endforeach;
    endif;
?> 

What can be done... Please help

1
  • Maybe the add_shortcode for two-third container is not returning a value within do_shortcode() again.
    – marcovega
    Commented Jul 2, 2015 at 11:13

2 Answers 2

1

I don't know why the code is not working. But this is how i did this may be helpful for some noob like me

<?php                  
    $name = get_the_content();          
    preg_match('/\[gallery ids="([^]]*)\"]/', $name, $match);                  
    $w3_ids = explode( ",", $match[1] ); 
    $gallery_count=1;
    foreach( $w3_ids AS $w3_id ): 
       $src = wp_get_attachment_image_src($w3_id,'full'); 
?>  
    <div class="item <?php if($gallery_count==1)echo "active"; ?>">
        <img src="<?php echo $src[0]; ?>" alt="" />
    </div>
<?php 
    $gallery_count++;
    endforeach;        
?>
-1
<?php
    $id=the_ID();
    $gallery_count = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' && ID=$id");
    echo $gallery_count;
?>

I think...!!! Try this for Particular gallery.

2
  • what would be $id
    – terminator
    Commented Jul 1, 2015 at 12:12
  • Please explain why this will solve the issue. Don't just dump code and tell someone to try it. Explain how your code works and how it should be used Commented Jul 1, 2015 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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