Support » Themes and Templates » [Plugin: NextGEN Gallery] Adding nextgen gallery in footer

  • Resolved rszczypka

    (@rszczypka)


    Hi,
    I would like to add the nextgen gallery in the footer of my website but I can’t find the php code to display gallery in any of the template files. Does anyone know how to do it?

    Thanks for any help

Viewing 10 replies - 1 through 10 (of 10 total)
  • Have a look into nggfunctions.php

    Thread Starter rszczypka

    (@rszczypka)

    I see that I should use the nggShowGallery($galleryID) function so e.g.
    <?php nggShowGallery(2) ?> but it doesn’t work

    I am beginner in php and can’t find how to access the function.

    I already did it moving the whole content from main content area into footer using javascript DOM but I would be very happy to know the solution.

    Thanks.

    Thread Starter rszczypka

    (@rszczypka)

    Thanks WhisperT!
    It works perfectly!

    Thread Starter rszczypka

    (@rszczypka)

    To have the gallery linked with the page I used the code:

    <?php $mygallerytitle = wp_title(' ', false); ?>
    <?php $footeralbum = '[gallery='.$mygallerytitle.']';
    $footeralbum = apply_filters('the_content', $footeralbum );
    echo $footeralbum; ?>

    It works when the title is only one word eg. ‘About’ and I have a gallery name ”About but it doesn’t work when I have page name ‘About us’ and gallery name ‘About us’.

    Is it any way to call the gallery by name or title?

    You would probably be better off using a custom field to store the id of the album and then calling that (less code too 😛 ). Mostly because currently I don’t think NextGen has a way to call a gallery by name built into it.

    So say we add a custom field to the page called meta_gallery_id and then make the value the id of your album. Then when you want to call that in the template you would do it like so:

    <?php
       $meta_id = $wp_query->post->ID; /* stores your post id in a variable */
    
    /* This stores the defined gallery ID into a variable.  Setting this to true makes sure it returns a string instead of an array */
       $meta_gallery_id = get_post_meta( $meta_id, 'meta_gallery_id', true );
       if( $meta_gallery_id != '' ) {
    	   $meta_gallery = '[gallery=' . $meta_gallery_id . ']';
    	   $meta_gallery= apply_filters( 'the_content', $meta_gallery );
    	   echo $meta_gallery;
    	 }
    ?>

    I’ve tested this on my sandbox site and it works as far as I can tell. Let me know how it works for you. 🙂

    Oh I forgot to mention all the work around code in that is set up because I’m assuming your using this outside of the loop. If your using it inside the loop things could be a little different.

    Thread Starter rszczypka

    (@rszczypka)

    Hi WhisperT,
    It works ok and I will use it when I don’t find the solution with gallery name.

    Thanks a million!

    Thread Starter rszczypka

    (@rszczypka)

    For all interested. I have just found the solution to get the gallery name in the template file and don’t have to use the custom field. Here is the code:

    <?php
     global $wpdb;
     $mygallerytitle = str_replace(" ", "-",strtolower(ltrim(wp_title(' ', false))));
     $mygalleryID =$wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE name = '$mygallerytitle'");
     $footeralbum = '[gallery='.$mygalleryID.']';
     $footeralbum = apply_filters('the_content', $footeralbum );
     echo $footeralbum;
    ?>

    NP rsczypka just figured the custom fields made it a bit more flexible too.

    There is a shorter way to accomplish cleaning up the title using the sanitize_title_with_dashes function already provided by WP.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: NextGEN Gallery] Adding nextgen gallery in footer’ is closed to new replies.