WordPress.org

Ready to get started?Download WordPress

Forums

Simple Lightbox
[resolved] Group image links by Post (9 posts)

  1. ivanbohatyr
    Member
    Posted 9 months ago #

    Hello,

    I'm using Simple Lightbox and it works great, but I can't group image links by Post (field in plugin settings checked) - probably because the code is outside the loop, so simple lightbox don't "see" separate posts.

    I was wondering if there is a way how to make my own groups for slideshow - rel attribute or maybe add some wrapper elements to make plugin "see" separate posts?

    Thanks

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

  2. ivanbohatyr
    Member
    Posted 9 months ago #

    Solved...

    to group images for slideshow do this: set 'data-slb-group="<?php echo $id ?>"' (where $id is id of your slideshow - post_ID perhaps) to wrapping 'a' tag on each image.

    So instead of trying some 'rel=lightbox[slideshow1]' try 'data-slb-group="slideshow1"' (set on 'a' tag, not 'img').

    Something like that could work:
    <a ... data-slb-group="<?php the_ID() ?>" data-slb-active="1" data-slb-internal="0"><img ...></a>

  3. Archetyped
    Member
    Plugin Author

    Posted 9 months ago #

    Hi, being outside of the loop should not affect whether or not link's in a post are grouped together or not. If the Group items by Post option is enabled then all content within a post should be grouped together.

    Can you post more details about how the content output to the page if it is not via a loop?

    A link to a page that exhibits the issue are experiencing would be very useful as well.

    Note that attributes such as data-slb-group are meant for internal use only and the implementation can change at any time. Manually modifying these attributes is not supported.

  4. ivanbohatyr
    Member
    Posted 9 months ago #

    Well, I work on this wordpress site within a company, so I rather do not public the url of this development site, on real site it's now done by data-slb-group as I posted.

    In functions.php there is a function that prints all posts in one category, each post has few thumbnails (by multiple thumbnails plugin). Via shortcode this function is invoked in a page. By get_posts() and get_the_post_thumbnail() all the thumbnails are displayed. Now I want to slideshow only these thumbnails, that are from one post. Problem is, that this (otherwise awesome) plugin does not recognize that and make slideshow for all thumbnails regardless which post they belong.
    I hope I cleared this issue well.

    Yes, "Group items by Post" is enabled, but just first option "Group items" has effect, others checked/unchecked has no effect in this case.

    I admit, that with new version data-slb-group attribut can change and actual solition will break, but I have no better solution yet.

    Thank for your time.

  5. Archetyped
    Member
    Plugin Author

    Posted 9 months ago #

    Ah, I see. As the posts are output to the page's content via shortcode, they are essentially part of that page when SLB activates the links. Therefore links will be grouped with anything else in the page's content, not grouped by post.

    So just for clarification, are you manually adding the data-slb-group attribute to the links in each post's content so that it will be there when you output the post's via the shortcode?

    Finally, what shortcode/plugin are you using to output the post's into the page's content? It may be possible to create an add-on for SLB to handle grouping within the shortcode's output.

  6. ivanbohatyr
    Member
    Posted 9 months ago #

    Yes, exactly -> data-slb-group attribut now is added directly to the link - see the code below.

    It my own shotcode, here is the part regarding this issue (code is simplified):

    $posts = array_reverse(get_posts( $args ));
    foreach ( $posts as $post ) {
      setup_postdata( $post );
      $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
      //first thumbnail<br />
      $output .= '<a href="' . $full_image_url[0] . '" title="' . the_title_attribute('echo=0'). ' | ' . $title . '">'.get_the_post_thumbnail(get_the_ID(), array(220, 170)).'</a>';
      if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail(get_post_type(), $seq.'-image', get_the_ID())) {
        //adding other thumbnails - like the first one
      }
    }
    wp_reset_postdata();

    And I want to make separate slideshows for each post.

  7. Archetyped
    Member
    Plugin Author

    Posted 9 months ago #

    To be fully compatible with WP's template tags (and SLB), the global $post object should be set to the post you are going to be accessing with template tags (such as get_the_ID(), etc.)

    See here for more information on using setup_post()

    For even better compatibility with WordPress (and plugins), using WP_Query to retrieve and loop through posts in your shortcode is highly recommended. This will make sure that the necessary global variables are properly set so that other code (such as SLB) can work with your custom post loop.

    More information on using WP_Query

    Doing either of these (the latter is recommended) things should allow SLB to detect each post in your custom loop and properly activate the links without you having to hardcode attributes in the shortcode.

  8. ivanbohatyr
    Member
    Posted 9 months ago #

    Thanks for swift reply, the code I posted was simplified to focus only on this issue, so staff like global $post I ommited on purpose (seemsed to be insignificant).

    But back to the topic - that's it, using WP_Query() instead of get_posts() solved the problem!

    I usually use WP_Query() when varied agruments are needed, so I thought in this case get_posts() is enough, but that was wrong...

    I really appreciate your help, thanks again.

  9. Archetyped
    Member
    Plugin Author

    Posted 9 months ago #

    Great, glad to help! Good to hear that you won't need to be hardcoding things.

Reply

You must log in to post.

About this Plugin

About this Topic