Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using a plugin, NextGEN gallery, to display photos. Each gallery from this plugin corresponds to a different sub-page, so I'm using conditional shortcodes to assign the right gallery to it's corresponding sub-page. Problem is, it's not working. I've used this exact setup before without issue, which leads me to believe that whatever is causing the problem now is probably something small I'm overlooking. I think a pair of fresh eyes would help out a lot. Thanks in advance.

ETA: I've also tried putting the corresponding shortcode directly in the sub-page, which needless to say didn't work.

gallery.php

<div class="content">
        <h2>PARLOUR GALLERY</h2>
        <div id="stylist-list">
            <h3><a href="index.php?page_id=39">REBECCA HAEHNLE</a> | <a href="index.php?page_id=41">CHRIS KELLER</a> | <a href="index.php?page_id=43">BILLY MALLOY</a> | <a href="index.php?page_id=45">VERONICA JONES</a> | <a href="index.php?page_id=47">ABBEY CASTELLANO</a> | <a href="index.php?page_id=49">QUARTIA FUTRELL</a> | <a href="index.php?page_id=51">ROOSEVELT OXENDINE</a> | <a href="index.php?page_id=53">NICOLE LUESCHOW</a> | <a href="index.php?page_id=55">MEREDITH NOWLIN</a> | <a href="index.php?page_id=57">MARICEL YALUNG</a> | <a href="index.php?page_id=59">STEPHANIE BRANDT</a> | <a href="index.php?page_id=61">JANNAH DIXON</a></h3>
        </div><!-- end stylist-list -->
        <div class="gallery">
                <?php     
                    if( is_page( 39 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=1]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 41 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=2]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 43 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=3]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 45 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=4]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 47 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=5]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 49 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=6]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 51 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=7]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 53 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=8]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 55 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=9]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 57 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=10]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 59 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=11]');
                    } else {
                      // output standard content here
                    }

                ?>
                <?php     
                    if( is_page( 61 ) ) {
                      // make your stuff here
                      echo do_shortcode('[nggallery id=12]');
                    } else {
                      // output standard content here
                    }

                ?>
        </div><!-- end gallery -->
    </div><!-- end content -->

functions.php

<?php function nggallery( $shortcode ){ echo do_shortcode( $shortcode ); /* NextGen Gallery */ } ?>
share|improve this question
    
Where does gallery.php come into play? Are you calling that from within your page.php template? If so, where? (Is it in The Loop, before or after The Loop) –  userabuser Sep 11 '12 at 13:53
    
gallery.php is the page template for the Gallery page. page.php is not utilized at all during this process, neither is The Loop. –  user1255049 Sep 11 '12 at 13:58
    
(ignore that - didn't see your update) –  userabuser Sep 11 '12 at 14:02
    
I assume you have assigned the page template to each of the sub-pages correct? Because if you've applied the page template only to the Gallery page, then the conditional statements are validating correctly because you are not on a sub-page and when you are, there's no template assigned to the sub-page to invoke the shortcode. –  userabuser Sep 11 '12 at 14:09
    
Yep, the subpages have all been assigned the Gallery template per gallery.php –  user1255049 Sep 11 '12 at 14:10

1 Answer 1

up vote 1 down vote accepted

As a test in the first conditional statement replace your //php comment in the else {} portion of your conditional with an actual echo statement to see whether the conditional is actually working properly,

<?php     
    if( is_page( 39 ) ) {
      // make your stuff here
      echo do_shortcode('[nggallery id=1]');
    } else {
      echo 'It works!';
    }

?>

Go to any of your sub-pages other than 39 of course, and you should see It works! print to screen which then suggests the problem lay more firmly with the plugin.

We need to ensure your conditional is validating properly first..

UPDATE

Seems you have a duplicate question posted here on August 21st which I stumbled across and so to your website and I can see the issue now.

The page id 39 corresponds to this URL,

http://www.yourdomain.com/rebecca-h/

...when navigating to that page you can see the gallery is working perfectly.

However when you are on your gallery page, i.e.,

http://www.yourdomain.com/gallery/

And you use any of the links within your code block,

<a href="index.php?page_id=39">REBECCA HAEHNLE</a>
<a href="index.php?page_id=41">CHRIS KELLER</a>
<a href="index.php?page_id=43">BILLY MALLOY</a>
...shortened for brevity

The URL in which your browser tries to retrieve is,

http://www.yourdomain.com/gallery/index.php?page_id=39

Which for all purposes is incorrect. In fact you'll notice that you can see the It works! statement echo out to the screen when trying to view Rebecca Haehnle's gallery which means that the conditional statement, although working, is validating as false instead of true.

Thus we are certainly not on the sub-page like you thought.

Instead, change your links to the following format,

<a href="<?php echo bloginfo('url'); ?>/index.php?page_id=39">REBECCA HAEHNLE</a>
etc...

This will print the top level domain name as your URL http://www.yourdomain.com before /index.php?page_id=XXgiving you a proper URL.

Alternatively you can use the permalink/slug instead of the ugly index.php?page_id=XX business like so,

<a href="<?php echo bloginfo('url'); ?>/rebecca-h/">REBECCA HAEHNLE</a>
etc...
share|improve this answer
    
Thanks for your help. How do I ensure the conditional is validating properly? I've replaced my original bit of code with the one you've provided, and it does seem to work. How can I go about tracking down the problem with the plugin? –  user1255049 Sep 11 '12 at 14:23
    
I'm not sure why you need to have that nggallery function placed within your functions.php file. I don't ever recall having to do that when using NextGEN in the past so please remove that temporarily and see whether that allows the shortcode to work properly. –  userabuser Sep 11 '12 at 14:26
    
Removed the nggallery bit from functions.php, no noticeable change to the gallery page. –  user1255049 Sep 11 '12 at 14:38
    
Please see my update for what I think is your problem/solution. –  userabuser Sep 11 '12 at 14:51
    
THANK YOU! RE: the duplicate, that question was from when I was originally trying to set all of this up. The methods provided there worked(which is why I said I had used my original set up before and it worked), however the site went down last night and I had to redo literally everything. When all was said and done, the gallery still wasn't working which is what brought me here again. Anyhow, everything is in perfect working order again. Thank you. –  user1255049 Sep 11 '12 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.