• bolide

    (@bolide-1)


    I am using a theme called Portfolium. I want to display an NGgallery slideshow in a portfolio page

    I have got as far as calling a Custom field (NGgallery id) but don’t know the syntax to parse the result correctly in single-portfolio.php which is the PHP that renders the portfolio page

    Simple stuff for you PHP experts:

    1 – do the [slideshow= bit – <?php include do_shortcode('[slideshow id='); ?>
    2 – pull out the gallery id – <?php $key="--nggalleryid"; echo get_post_meta($post->ID, $key, true); ?>
    3 – put the end on the slideshow tag – <?php include ' w=785 h=521]'; ?>

    OK, this PHP outputs the gallery code but doesn’t parse it to show the gallery

    <?php echo'[slideshow id='; $key="--nggalleryid"; echo get_post_meta($post->ID, $key, true); echo ' w=785 h=521]'; ?>

    This outputs [slideshow id=1 w=785 h=521] – that code, in a page or post, brings up a NGG gallery but my code is showing the shortcode, not parsing it

    Help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your syntax is a bit messy.

    To execute a shortcode, you call the do_shortcode() function, with the full, bracket-enclosed shortcode piece as the only parameter in the function call.

    Ex:
    <?php do_shortcode('[slideshow id=1 w=785 h=521]'); ?>

    You’ve figured out how to get all the pieces you need together, however, you’re outputting them, and that’s exactly what you’re getting – output.

    What you’ll want to do is build a string variable in PHP, concatenate all the bits of the shortcode together, and then pass this variable to the do_shortcode() function call.

    a la:

    $shortcode_parameter = '[slideshow id=' . get_post_meta($post->ID, '--nggalleryid', true) . ' w=785 h=521]';
    do_shortcode($shortcode_parameter);
    Thread Starter bolide

    (@bolide-1)

    Eric

    Many thanks for that. I understand the idea but had no idea how to do that. I imagine $shortcode_parameter is the string variable, you set it up and then execute it using do_shortcode($shortcode_parameter)

    Very neat. I think I’ll look into PHP a bit more as, once you have the right direction, it’s not too tough

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP syntax help wanted’ is closed to new replies.