WordPress.org

Ready to get started?Download WordPress

Forums

NextGEN Gallery
[resolved] Completely weird behaviour with custom templates (2 posts)

  1. Ricardo
    Member
    Posted 2 years ago #

    I'm using NGG 1.8.3 over WP 3.2.1 Multisite.

    I'm calling two galleries directly from the templates with this lines:

    echo do_shortcode('[nggallery id=1]');
    echo do_shortcode('[nggallery id=2]');

    And I'm using a custom NGG template, located in a folder called /nggallery/ inside the theme folder. The customized gallery.php file looks like this:

    <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?><?php if (!empty ($gallery)) : ?>
    
    	<?php
    	$total_imagenes = sizeof($images);
    	for ( $i=1; $i<=$total_imagenes; $i++ ) {
    		if ( !$images[$i]->hidden ) {
    			echo '<a href="' . $images[$i]->imageURL . '" title="' . $images[$i]->description . '" rel="shadowbox[' . $gallery->anchor . ']" ';
    			if ($i==1) echo 'id="fotosStart" ';
    			echo '></a>';
    		}
    		if ( $images[$i]->hidden ) continue;
    	}
    	?>
    
    <?php endif; ?>

    Gallery ID 2 works perfectly fine; the weirdness is related to gallery ID 1. It generates the HTML for all the images, but it won't pull the image URL, title or description from $images.

    Any ideas?

    (of course, thanks in advance for any help you may provide)

    http://wordpress.org/extend/plugins/nextgen-gallery/

  2. Ricardo
    Member
    Posted 2 years ago #

    I figured it out, so here is the answer in case of any of you should be looking to solve a similar issue.

    <?php
    if (!defined ('ABSPATH')) die ('No direct access allowed');
    
    if (!empty ($gallery)) :
    
    	$firstImage = true;
    	foreach ($images as $image) {
    		if ( !$image->hidden ) {
    			echo '<a href="' . $image->imageURL . '" title="' . $image->description . '" rel="shadowbox[' . $gallery->anchor . ']" ';
    			if ($firstImage) {
    				echo 'id="fotosStart" ';
    				$firstImage = false;
    			}
    			echo '></a>';
    		}
    		if ( $image->hidden ) continue;
    	}
    
    endif;
    ?>

    Apparently, it's better to use foreach to go through arrays.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic