• 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?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter John Leschinski

    (@picard102)

    Got it.

    <?php $gallery = get_post_meta($post->ID, 'gid', true);
    $gal = $gallery;
    $gal = apply_filters('the_content', '[gallery='.$gal.']' );
    echo $gal;
    ?>

    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.

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

    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:
    https://whatsnewonsale.com/fs_wp/collections-2/

    to pass an id to this page:
    https://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:

    https://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

    @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

    @ 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?

    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.

    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..

    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;
    	?>

    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.

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

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘NextGen Gallery in Template.’ is closed to new replies.