Forums

[resolved] NextGen Gallery in Template. (12 posts)

  1. picard102
    Member
    Posted 2 years ago #

    I'm looking to put the short code for NextGen Gallery directly into my template and pass the ID of the gallery to it via a custom field.

    So far I know how to grab the short code,
    <?php echo do_shortcode('[nggallery id=]'); ?>

    And grab the custom field,
    <?php echo get_post_meta($post->ID, "gid", true);?>

    But I can't seem to make them work together.
    Anyone have any ideas on how I can pass the value from gid to the id in the short code?

  2. picard102
    Member
    Posted 2 years ago #

    Got it.

    <?php $gallery = get_post_meta($post->ID, 'gid', true);
    $gal = $gallery;
    $gal = apply_filters('the_content', '[gallery='.$gal.']' );
    echo $gal;
    ?>
  3. brian420
    Member
    Posted 2 years ago #

    You sir, are awesome. I was unaware you could echo shortcodes like that and I was looking for a standalone way to embed the slideshow on my index page. Thanks for the pro-tip.

  4. relish1227
    Member
    Posted 2 years ago #

    Yay!! This is exactly what I was looking for. Thank you.

  5. bzappster
    Member
    Posted 2 years ago #

    picard and brian. I am not a php pro like you guys but I want to output a next gen pic on a page who's pic id was passed from another page who's gallery id was passed from yet another page (whew!)

    I don't have any templates. just the nggallery.php and basic files.

    can you tell me what code to write and where to place it?

    specifically I need this page's green links:
    http://whatsnewonsale.com/fs_wp/collections-2/

    to pass an id to this page:
    http://whatsnewonsale.com/fs_wp/collections-2/collections-index/

    who's thumbnails pass a pic id to this page to display the pic with the pass id:

    http://whatsnewonsale.com/fs_wp/detail-page/

    or maybe you have better ideas.

    again, I don't know what to write in my code or where to place it.

    thanks and any help would be greatly appreciated

    BZ

  6. get_username
    Member
    Posted 1 year ago #

    @picard102

    Where did you place this code in the loop?
    Was the Custom Field name Gallery or Gal?
    What was the value of the Custom Field, or is that just the gallery number?
    Anything else I'm missing for implementing this?

    Thanks

  7. Rhand
    Member
    Posted 1 year ago #

    @ get_username Did you ever figure out where to place it in the loop? Was it just the gallery ID number you had to add?

  8. Rhand
    Member
    Posted 1 year ago #

    Never mind. Working now. Added gid as custom field and entered ID number of choice. Now I just need to figure a way to use the NGG template of choice.

  9. Rhand
    Member
    Posted 1 year ago #

    Using:

    <?php /* NG Gallery Custom Field Rotating Images  */
    	$gallery = get_post_meta($post->ID, 'gid', true);
    	$gal = $gallery;
    	$gal = apply_filters('the_content', '[gallery='.$gal.' template="resort"]' );
    	echo $gal;
    	?>

    now, but somehow it does not pick up my own template in themes/my-theme/nggallery/gallery-resort. This is a copy of the carousel template, but no carousel with four images is shown. It shows two thumbnails, one being the featured image. Wonder why..

  10. Rhand
    Member
    Posted 1 year ago #

    Added ngallery/gallery-resort to parent theme to see if that helped. No luck just yet. Still two thumbnails instead of a carousel..

    Current code:

    <?php /* NG Gallery Custom Field Rotating Images  */
    	$gallery = get_post_meta($post->ID, 'gid', true);
    	$gal = $gallery;
    	$gal = apply_filters('the_content', '[gallery='.$gal.' template=resort]' );
    	echo $gal;
    	?>
  11. get_username
    Member
    Posted 1 year ago #

    Hi Rhand,

    It worked for me once I changed the meta value to the name of my custom field. In the original code get_post_meta($post->ID, 'gid', true); the meta value "gid" should be changed to whatever you're using for a custom field name. As soon as those two matched it started to work.

  12. Rhand
    Member
    Posted 1 year ago #

    Thanks get_username. Got it working just an hour or two ago. Got it to load my chosen NGG template as well.

Topic Closed

This topic has been closed to new replies.

About this Topic