Support » Plugin: NextGEN Custom Fields » Gallery ID not loading into Custom Template

  • Resolved jeffppwd

    (@jeffppwd)


    I’m hoping you can help me with this problem. The gallery’s ID won’t load into my custom template. It works fine for the images custom fields tag, and it works fine if I manually put the number of a gallery into the gallery custom fields tag, but even using the bit of code suggested here does not work.

    <?
    if(is_object($displayed_gallery) && isset($displayed_gallery->container_ids)) {
    	if(count($displayed_gallery->container_ids) == 1 && is_numeric($displayed_gallery->container_ids[0])) {
    		$gid = $displayed_gallery->container_ids[0];
    	}
    }
    ?>
    <?php echo nggcf_get_gallery_field($gid, "Your Gallery Field Name"); ?>

    — It’s not a matter of deleting the cache.
    — I don’t think it’s a matter of not using the right template because it’s a custom template and I see the other changes I’m making.
    — I do get an echo’d result if I put in a regular

    <p><?php echo $gallery->ID; ?></p>

    — But not if it is used in the nggcf_get_gallery_field tag.
    — Also do not get a result if I try:

    <p><?php echo $gid; ?></p>

    Here is my custom gallery template’s full php:

    <?php
    /**
    Template Page for the gallery overview
    
    Follow variables are useable :
    
    	$gallery     : Contain all about the gallery
    	$images      : Contain all images, path, title
    	$pagination  : Contain the pagination content
    
     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'] ?>
    **/
    ?>
    <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?><?php if (!empty ($gallery)) : ?>
    <h2 class="gallery-title"><?php echo $gallery->title ?></h2>
    
    <?php //** Suggested additional code from Shauno (plugin author) **// ?>
    <?php
    if(is_object($displayed_gallery) && isset($displayed_gallery->container_ids)) {
    	if(count($displayed_gallery->container_ids) == 1 && is_numeric($displayed_gallery->container_ids[0])) {
    		$gid = $displayed_gallery->container_ids[0];
    	}
    }
    ?>
    
    <?php //** Here are the test echos **// ?>
    <p>
    Echo Result of $gid:
    <?php echo $gid; ?><br>
    Echo Result of $gallery->ID:
    <?php echo $gallery->ID; ?><br>
    Echo Result using Original $gallery->ID method:
    <?php echo nggcf_get_gallery_field($gallery->ID, "eflmgallerylink"); ?><br>
    Echo Result using $gid method:
     <?php  echo nggcf_get_gallery_field($gid, "eflmgallerylink"); ?></p>
    
    <div class="ngg-mandf-galleryoverview" id="<?php echo $gallery->anchor ?>">
    
      <?php if ($gallery->show_slideshow) { ?>
      <!-- Slideshow link -->
    <div class="slideshowlink">
    		<a class="slideshowlink" href="<?php echo nextgen_esc_url($gallery->slideshow_link) ?>">
    			<?php echo $gallery->slideshow_link_text ?>
    		</a>
    	</div>
    <?php } ?>
    
    <?php if ($gallery->show_piclens) { ?>
    	<!-- Piclense link -->
    	<div class="piclenselink">
    		<a class="piclenselink" href="<?php echo nextgen_esc_url($gallery->piclens_link) ?>">
    			<?php _e('[View with PicLens]','nggallery'); ?>
    		</a>
    	</div>
    <?php } ?>
    
    	<!-- Thumbnails -->
        <?php $i = 0; ?>
    	<?php foreach ( $images as $image ) : ?>
    
    	<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-mandf-gallery-thumbnail-box" <?php echo $image->style ?> >
    		<div class="ngg-mandf-gallery-thumbnail" >
    			<a href="<?php echo nextgen_esc_url($image->imageURL) ?>"
                   title="<?php echo esc_attr($image->description) ?>"
                   data-src="<?php echo nextgen_esc_url($image->imageURL); ?>"
                   data-thumbnail="<?php echo nextgen_esc_url($image->thumbnailURL); ?>"
                   data-image-id="<?php echo esc_attr($image->pid); ?>"
                   data-title="<?php echo esc_attr($image->alttext); ?>"
                   data-description="<?php echo esc_attr($image->description); ?>"
                   <?php echo $image->thumbcode ?> >
    				<?php if ( !$image->hidden ) { ?>
    				<img alt="<?php echo esc_attr($image->alttext) ?>" src="<?php echo nextgen_esc_url($image->thumbnailURL) ?>" <?php echo $image->size ?> />
    				<?php } ?>
    			</a>
    		</div>
    	</div>
    
        <?php if ( $image->hidden ) continue; ?>
        <?php if ($gallery->columns > 0): ?>
            <?php if ((($i + 1) % $gallery->columns) == 0 ): ?>
                <br style="clear: both" />
            <?php endif; ?>
        <?php endif; ?>
        <?php $i++; ?>
    
     	<?php endforeach; ?>
    
    	<!-- Pagination -->
     	<?php echo $pagination ?>
    
    </div>
    
    <?php endif; ?>

    https://wordpress.org/plugins/nextgen-gallery-custom-fields/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I SOLVED IT!

    The problem is that I am using NextGEN Basic Thumbnail, so even though my template is custom, it is a LEGACY template.

    I yanked the following bit of code from here:
    http://hookr.io/functions/nggv_gallery_vote_form/

    <?php
      if(isset($gallery->displayed_gallery) && isset($gallery->displayed_gallery->container_ids)) {
                if(count($gallery->displayed_gallery->container_ids) == 1 && is_numeric($gallery->displayed_gallery->container_ids[0])) {
                    $gid = $gallery->displayed_gallery->container_ids[0];
                }
            }
    ?>

    Then put $gid into the Custom Fields tag replacing the $gallery->ID, like so:

    <?php echo nggcf_get_gallery_field($gid, "Your Gallery Field Name"); ?>

    Ba Boom!

    Thanks for posting about this! I was having issues getting my field information. the $gid and extra code worked beautifully!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Gallery ID not loading into Custom Template’ is closed to new replies.