• Hello,
    First off; love the plugin, its so easy ?? !!

    I was wondering if its possible if there is a way to echo just the img tags inside a template file?

    Background:
    In my theme there is a slider function already built in, which uses the core gallery function. Like this:

    <ul class="slides">
    <?php
    $post_content = get_the_content();
    preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
    $array_id = explode(",", $ids[1]);
    $content =  str_replace($ids[0], "", $post_content);
    $filtered_content = apply_filters( 'the_content', $content);
    foreach($array_id as $img_id){ ?>
    								<li><?php echo wp_get_attachment_image( $img_id, 'full' ); ?></li>
    
    <?php } ?>
    </ul>

    But for a lot of reasons I dont want to use the built in theme slider. So im thinking of using the Easy Image Gallery Plugin instead.

    I have tried this:

    <ul class="slides">
    <?php
    $post_content = get_the_content();
    preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
    $array_id = explode(",", $ids[1]);
    $content =  str_replace($ids[0], "", $post_content);
    $filtered_content = apply_filters( 'the_content', $content);
    foreach($array_id as $img_id){ ?>
    								<li><?php if( function_exists( 'easy_image_gallery' ) ) { echo easy_image_gallery(); } ?></li>
    
    <?php } ?>
    </ul>

    And it works kind of, but its echoing the whole Easy Image Gallery code, with ul and li and everything. So is it possible to just echo the img tags somehow?

    Thanks in advance!

    Kind regards,
    Richard

    https://www.ads-software.com/plugins/easy-image-gallery/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Sure, have a look inside the plugin at the easy_image_gallery_get_image_ids() function. This will get the image IDs for you from the database. From there you can write a foreach loop and use WordPress’ wp_get_attachment_image_src() function to get the image paths. Have a look at the easy_image_gallery() function, I do just that to build out the HTML.

    Thread Starter Skaerby

    (@skaerby)

    I have tried, and my php skills is just not enough to make this work. Where should i write the foreach loop, inside the theme file or inside easy gallerys template-functions.php?

    If you make modifications to the plugin itself they will be lost when it is updated. You can either write the foreach loop in your child theme’s functions.php or make another plugin to add the code to.

    <?php
        $gallery_images = easy_image_gallery_get_image_ids();
        foreach($gallery_images as $image_id) { // looping on user-selected attachment IDs
         $image_src = wp_get_attachment_url( $image_id ); // returns an array
         $image_thumb_src = wp_get_attachment_url( $image_id, 'thumbnail' ); // returns an array
         echo '<div class="col-xs-4 col-md-2">
              <a href="'.$image_src.'" data-gallery="global-gallery" data-parent="" data-toggle="lightbox" class="thumbnail">
               <img src="' . $image_thumb_src . '" class="img-responsive" alt="">
              </a>
            </div>';
        }
        ?>

    Thanks for the plugin, this is what I’m using, works like a charm!

    Great!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Someway to just echo the img tags?’ is closed to new replies.