• Resolved azurays

    (@azurays)


    I am reading installation instructions here – https://archetyped.com/lab/slb-2-3-0/ – but can’t quite figure out how to implement into the page template. It’s working perfectly with the native image gallery, but I’m trying to get it to work with an image map I have hard coded into a template page. I’m not the best at php.

    Would you be able to provide an example integrating with –

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content(‘Read more…’); ?>
    <?php endwhile; else: ?>
    <?php endif; ?>

    Thank you in advance!

    https://www.ads-software.com/plugins/simple-lightbox/

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

    (@archetyped)

    When using the_content() SLB handles things automatically, so the template code you posted should work fine with SLB.

    Please provide a link to a page that exhibits the issue you are experiencing so that it can be evaluated further.

    Thread Starter azurays

    (@azurays)

    Ah sorry I realized the images that I want to lightbox actually not in the_content, but rather hard coded into the template page, after the_content. I tried applying a rel=’slb’ into the <area that contained the image but that didn’t seem to work. Would I be able to email you the link?

    Thank you!!

    Plugin Author Archetyped

    (@archetyped)

    You can save the hard-coded content that you want to output in the template to a variable and pass it through slb_activate()

    Example:

    $content = 'content with links and stuff to activate';
    if ( function_exists('slb_activate') )
        $content = slb_activate($content);
    echo $content;
    

    If you’re still having trouble, you can email the link to [email protected]

    I am trying to get this to work on a blog template that I made to pop out the featured thumbnail images, but I can’t figure out how to implement this. How would it fit into this example?

    <?php 
    
     	   if ( has_post_thumbnail()) {
       	     $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large');
       	     echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . ' ">';
       	     echo get_the_post_thumbnail($post_id, 'thumbnail', array('class' => 'alignleft'));
       	   echo '</a>';
     	  }
    	?>

    Thanks!

    Plugin Author Archetyped

    (@archetyped)

    Hi,

    Instead of echoing the link directly, simply save the generated output to a variable (e.g. $content) and then pass it through slb_activate().

    In other words, take the example I previously posted, replace the ‘content with links and stuff to activate’ text with your link’s text.

    I’ve tried to cobble it together similarly to the person above, and I feel quite close to getting it to work, but it’s not putting the link around the image. Instead the link is after the image and thus useless. Can you tell what’s going on? I’ve tried to combine the code from Post Thumbnail Linking to Large Image Size (but to the full image, hence the lightbox):

    <?php
    if ( has_post_thumbnail() ) {
    	$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
    	echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute( 'echo=0' ) . '">';
    	the_post_thumbnail( 'thumbnail' );
    	echo '</a>';
    }
    ?>

    With Simple Light Box | Activate Anywhere | Usage:

    $content = 'content with links and stuff to activate';
    if ( function_exists('slb_activate') )
        $content = slb_activate($content);
    echo $content;

    To make:

    <!-- ADD FEATURED IMAGE & LINK TO FULL IMAGE -->
    		<?php
    		if ( has_post_thumbnail() ) {
    			$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    			$echo1 = '<a href="' . $full_image_url[0] . '" title="' . the_title_attribute( 'echo=0' ) . '">';
    			$middle = the_post_thumbnail( 'large' );
    			$echo2 = '</a>';
    			$content = $echo1 . $middle . $echo2;
    			if ( function_exists('slb_activate') ) {
    				$content = slb_activate($content);
    			echo $content;
    			}
    		}
    		?>

    Thank you for Simple Light Box!

    Thinking that maybe the variables were messing things up I’ve removed $echo1, $middle & $echo2, to prevent the_post_thumbnail from showing up before the html is inserted in front of the image, but that didn’t solve the problem.

    <?php
    if ( has_post_thumbnail() ) {
    	$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    	$content = '<a href="' . $full_image_url[0] . '" title="' . the_title_attribute( 'echo=0' ) . '">' . the_post_thumbnail( 'large' ) . '</a>';
    	if ( function_exists('slb_activate') ) {
    		$content = slb_activate($content);
    	echo $content;
    	}
    }
    ?>

    haha! I got it. I couldn’t figure out how to NOT display the_post_thumbnail. Turns out you don’t use the_post_thumbnail if you don’t want it displayed. Instead you use get_the_post_thumbnail which seems to get the html string, but doesn’t display it until you echo. Here’s what it says in the codex:

    Note: To return the Post Thumbnail for use in your PHP code instead of displaying it, use: get_the_post_thumbnail()

    With this method you then use echo later and to have it displayed within the link.

    So, if you’re trying to display a large thumbnail (featured image) above your postContent div that links to the full image size and is picked up by Simple Light Box, this should work:

    <!-- ADD LARGE FEATURED IMAGE & LINK TO FULL IMAGE -->
    <?php
    if ( has_post_thumbnail() ) {
    	$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    	$content = '<a href="' . $full_image_url[0] . '" title="' . the_title_attribute( 'echo=0' ) . '">' . get_the_post_thumbnail( $post_id, 'large' ) . '</a>';
    	if ( function_exists('slb_activate') ) {
    		$content = slb_activate($content);
    	echo $content;
    	}
    }
    ?>

    Seems super basic now, but this is my first “written” (cobbled together) php.

    Plugin Author Archetyped

    (@archetyped)

    Awesome! Apologies for not getting back to you sooner, but the solution you found is on point. Great job ??

    Thanks! ??

    Hi,

    this fix seems to be exactly what I would need but my knowledge of php is not enough to understand how to implement it. Would anyone care to give me more exact instructions?

    Do I put this piece of code in my page template?

    All help will be much appreciated!

    Plugin Author Archetyped

    (@archetyped)

    @textografiskt: Yes, the above code snippet can be added to your page template.

    If you have further questions, I would suggest creating a new ticket in SLB’s official support forum so that your particular questions can be answered more specifically.

    Here is an update to this thread that both puts the code in context and ensures that the featured image will still be displayed even if Simple Lightbox (SLB) is deactivated. I’ve included the whole upper portion of my child theme’s single.php file to show where I’ve placed the php code for adding the featured image and simple lightbox. The update moves the } above echo $content; instead of below, which will ensure it’s displayed even if slb_activate does not exist.

    <?php get_header(); ?>
    
    <div id="coreContent">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
          <div class="post single hentry">
           <h5 class="entry-title"><abbr class="published"><?php the_title(); ?></abbr></h5>
    
            <!-- ADD FEATURED IMAGE & SLB LINK TO FULL IMAGE -->
    		<?php
    		if ( has_post_thumbnail() ) {
    			$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    			$content = '<a href="' . $full_image_url[0] . '" title="' . the_title_attribute( 'echo=0' ) . '">' . get_the_post_thumbnail( $post_id, 'large' ) . '</a>';
    			if ( function_exists('slb_activate') ) {
    				$content = slb_activate($content);
    				}
    			echo $content;
    		}
    		?>
    
            <div class="postContent">
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Help activating SLB in my theme’ is closed to new replies.