WordPress.org

Ready to get started?Download WordPress

Forums

singlepic-caption template (1 post)

  1. istarnet
    Member
    Posted 3 years ago #

    I looked for a convenient way to place captions beneath floated images but I had no luck searching. Here is my solution which I hope might help others.

    First, I needed to know, within a template, whether the image was floated left or right, so I modified nggfunctions.php. For version 1.6.2 this change occurs on or about line 808:

    insert into line: , 'float' => $float

    resulting in

    $out = nggGallery::capture ( $filename, array ('image' => $picture , 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db, 'float' => $float) );

    Now you'll have access to a new variable named $float inside your template. I named my template: singlepic-caption

    Within the views folder create a file named singlepic-caption.php containing:

    <?php
    /**
    Template Page for the single pic with a caption - additions by Mark Levine www.istarnet.com
    
    Follow variables are useable :
    
    	$image : Contain all about the image
    	$meta  : Contain the raw Meta data from the image
    	$exif  : Contain the clean up Exif data from file
    	$iptc  : Contain the clean up IPTC data from file
    	$xmp   : Contain the clean up XMP data  from file
    	$db    : Contain the clean up META data from the database (should be imported during upload)
    	$float : Contains the class to position the caption, eg. ngg-right
    
    Please note : A Image resize or watermarking operation will remove all meta information, exif will in this case loaded from database 
    
     You can check the content when you insert the tag <?php var_dump($variable) ?>
     If you would like to show the timestamp of the image ,you can use <?php echo $exif['created_timestamp'] ?>
    **/
    
    if (!defined ('ABSPATH')) die ('No direct access allowed');
    
    if (!empty ($image)) :
    	echo '<p class="ngg-singlepic-caption'.$float.'" style="width:'.(8+$image->width).'px;';
    	// insert a margin style if the image is floated
    	switch($float) {
    	case ' ngg-left':
    		echo 'margin:0 10px 0 0';
    		break;
    	case ' ngg-right':
    		echo 'margin:0 0 0 10px;';
    		break;
    	default:
    		break;
    	}
    	echo '">';
    
    	echo '<a href="'.$image->imageURL.'" title="'.$image->linktitle.'" '.$image->thumbcode.' >';
    	echo '<img';
    	echo ' src="'.$image->thumbnailURL.'"';
    	echo ' alt="'.$image->alttext.'"';
    	echo ' title="'.$image->alttext.'"';
    	echo ' />';
    	echo '</a>';
    	if (!empty ($image->description)) :
    		echo $image->description;
    	endif;
    	echo '</p>';
    endif;

    Now you can use [ singlepic id=N template=caption float=right ]

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by istarnet
  • This topic is not a support question
  • WordPress version: 3.0.1