Title: singlepic-caption template
Last modified: August 19, 2016

---

# singlepic-caption template

 *  [istarnet](https://wordpress.org/support/users/istarnet/)
 * (@istarnet)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/singlepic-caption-template/)
 * 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 ]

The topic ‘singlepic-caption template’ is closed to new replies.

## Tags

 * [caption](https://wordpress.org/support/topic-tag/caption/)
 * [float](https://wordpress.org/support/topic-tag/float/)
 * [singlepic](https://wordpress.org/support/topic-tag/singlepic/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [istarnet](https://wordpress.org/support/users/istarnet/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/singlepic-caption-template/)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
