WordPress.org

Ready to get started?Download WordPress

Forums

NextGEN Gallery
[resolved] [PLUGIN: NEXTGEN GALLERY]display number instead of ID (9 posts)

  1. stefsegers
    Member
    Posted 3 years ago #

    Hi guys,

    I am working on a NextGen Template and want to display a number of a picture. I know it's possible to show the image ID but when you add new pictures you get higher ID's and I just want to show number from 1 till ...

    The fist image would be 1 second 2 etc.

    It's like numbering the array of images and outputting them.

    Since I am not a programmer it's difficult to understand the PHP count/for each/array you name it. I think this shouln't be difficult at all but I need some tips.

    I also tried <?php var_dump($image) ?>
    but there's no array numer/image number from the array.

    Hope somebody can help me out here?

  2. Joseph
    Member
    Posted 3 years ago #

    If you just want to number the images, simply add a counter by changing

    <?php foreach ( $images as $image ) : ?>

    to something like

    <?php $img_counter = 0;
    foreach ( $images as $image ) : ++$img_counter; ?>

    and use

    <?php echo $img_counter; ?>

    wherever you want the number to be.

  3. stefsegers
    Member
    Posted 3 years ago #

    Hi Joseph,

    Wauw is it that easy? Still have no idea how to figure out what it exactly means but it works.

    http://www.trouwshoot.nl/foto-gallerij

    The only thing is that when you go to the next page the counter starts all over again. Is there a way to solve this?

    Stefan

  4. Joseph
    Member
    Posted 3 years ago #

    Each image in the gallery is outputted through a loop and all I did was add a counter which increase by 1 for every loop.

    To prevent the counter from resetting, replace

    <?php $img_counter = 0;
    foreach ( $images as $image ) : ++$img_counter; ?>

    with

    <?php $nggpage = get_query_var('nggpage');
    if (!empty($nggpage)) {
    	$ngg_options = nggGallery::get_option('ngg_options');
    	$img_counter = ($nggpage - 1) * (int) $ngg_options['galImages'];
    } else {
    	$img_counter = 0;
    }
    foreach ( $images as $image ) : ++$img_counter; ?>

    The extra bit of code calculates the starting number of the counter base on the number of images per page and the current page number.

  5. stefsegers
    Member
    Posted 3 years ago #

    You are like a magician! Thank you very much for your help. I just implemented it on the website Works like a charm!

  6. Joseph
    Member
    Posted 3 years ago #

    You're welcome. :)

  7. sdjentertainment
    Member
    Posted 3 years ago #

    Hi There,

    I am having the same problem stefsegers, I've tried implementing the code in a number of spots, but still couldn't work it out. I was just wondering where you would put the following code?

    <?php $nggpage = get_query_var('nggpage');
    if (!empty($nggpage)) {
    	$ngg_options = nggGallery::get_option('ngg_options');
    	$img_counter = ($nggpage - 1) * (int) $ngg_options['galImages'];
    } else {
    	$img_counter = 0;
    }
    foreach ( $images as $image ) : ++$img_counter; ?>

    Thanks in advance,

    Cheers,
    Simon

  8. stefsegers
    Member
    Posted 3 years ago #

    Hi Simon,

    I made a directory in my Theme dir called "nggallery"
    within this dir I made a file called "gallery-trouwshoot.php"

    NG GAllery will check the theme dir if it finds a NGGALLERY dir and uses the templates from there. This way you will be able to update NG without removing the template files.

    This is my code of the template:

    <?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)) : ?>
    
    		<?php if ($prev) : ?>
    			<a class="prev" href="<?php echo $prev ?>"><<<</a>
    		<?php endif; ?>
    
    <?php $nggpage = get_query_var('nggpage');
    if (!empty($nggpage)) {
    	$ngg_options = nggGallery::get_option('ngg_options');
    	$img_counter = ($nggpage - 1) * (int) $ngg_options['galImages'];
    } else {
    	$img_counter = 0;
    }
    foreach ( $images as $image ) : ++$img_counter; ?>
    
    <a href="javascript:void(0)"><?php echo $img_counter; ?><img title="<?php echo $image->meta_data['keywords'] ?>" alt="<?php echo $image->alttext ?>,<?php echo $image->description ?>" src="<?php echo $image->url ?>" /></a>
    
     <?php if ( $image->hidden ) continue; ?>
     <?php $imgCounter++;?>
     <?php endforeach; ?>
    
    		<?php if ($next) : ?>
    			<a class="next" href="<?php echo $next ?>">>>></a>
    		<?php endif; ?>
    </div>
    
    <?php endif; ?>

    But over here I have problems again :( it's not working anymore.

    Also the second page won't appear. So my first 20 files will appear and the next page button does work, but goes back to the first page.

  9. sdjentertainment
    Member
    Posted 3 years ago #

    Hey,

    Thanks for taking the time to explain this. I didn't know the trick about making a folder in the theme folder. That will come in handy in the future.

    Thanks again, and all the best in the new year.

    Cheers,
    Simon

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic