• Resolved sagitt000

    (@sagitt000)


    Hi, can you please help me in this situation? It took me more time than i thought.
    Basically, i created a page template that retrieves images (attachment) as posts by specific category. And everything works fine, except one. I can’t group those images, i have googled many times to find solution, even with shortcode. But nothing works. That’s why i can’t choose “Next” or “Previous” when lightbox appears. Each piece has different slb ID. I hope you could help me. Thank you!

    <?php
     * Template Name: Testy
    get_header();
    ?>
    <div id="primary" class="content-area">
      <main id="main" class="site-main" role="main">
        <?php
          $attachments = array(
          'post_type' => 'attachment',
          'post_status' => array('publish', 'inherit'),
          'category_name'    => 'sagitt',
          'numberposts' => -1,
          'posts_per_page' => 10,
          'paged' => $paged,
          );
          query_posts($attachments);
        ?>
        <div class="gallery">
          <?php while (have_posts()) : the_post(); ?>
            <figure class="gallery-item">
              <?php the_content(); ?>
            </figure>
          <?php endwhile ?>
        </div>
      </main><!-- .site-main -->
    </div><!-- .content-area -->
    <?php get_footer(); ?>

    https://wordpress.org/plugins/simple-lightbox/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Archetyped

    (@archetyped)

    Hi, when you use the_post() to load and output each attachment, SLB’s “Group items by Post” setting will put each attachment in a separate group. Unchecking this option in SLB’s settings will allow all items be grouped together.

    Another option is to build a [gallery] shortcode for the attachments and then activate the shortcode using do_shortcode() & slb_activate() like so:

    // Build gallery...
    $gallery = '[gallery ids={ids here}]';
    
    // Generate code from shortcode
    $gallery = do_shortcode($gallery);
    
    // Activate and output links in gallery
    echo slb_activate($gallery);
    

    You can even define your own specific group for the gallery:

    // Activate and output links in gallery
    echo slb_activate($gallery, 'my-special-group');
    

    One of the main benefits of doing things this way is that SLB is only called once to activate links, rather than separately for each attachment, as when a post loop is used.

    Thread Starter sagitt000

    (@sagitt000)

    Whoa, it indeed works now! Just uncheck that option, very easy trick, i must find out from the beginning. Thank you very much! Have a good day!

    Plugin Author Archetyped

    (@archetyped)

    Awesome, glad to hear it 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Grouping images’ is closed to new replies.