Forums

Can You Displaya post's gallery on Home Page Excerpts... (4 posts)

  1. andymacdonalduk
    Member
    Posted 2 years ago #

    Hey Guys,

    I am currently using this piece of code: "<?php echo do_shortcode('[gallery columns="5"]'); ?>" to display a post's gallery on the home page excerpts.

    I wanted to know if there was any way to display the gallery ONLY if a gallery of pictures has been inserted into the post.

    The way it works currently is it will display any pictures which has been inserted into a post on the home page, but i only want the pictures to be displayed IF a full gallery of pictures has been inserted into a post.

    I.E, if [gallery] tag appears in the post.

    Any advice will be very much appreciated.
    Andrew

  2. Michael Fields
    Theme Wrangler
    Posted 2 years ago #

    Something like this should work for you - inside the loop of course...

    <?php
    if ( strstr( $post->post_content, '[gallery' ) )
        echo do_shortcode('[gallery columns="5"]');
    ?>
  3. andymacdonalduk
    Member
    Posted 2 years ago #

    That actually worked perfectly for me. Thank you very much sir!!!

  4. Michael Fields
    Theme Wrangler
    Posted 2 years ago #

    You're welcome sir!

Topic Closed

This topic has been closed to new replies.

About this Topic