Jump to content

[SOLVED] If-else statement using isset creates blank output


yotamono

Recommended Posts

Okay I've got a straightforward question. Why doesn't this work?

 

<?php if (isset($_GET['s'])) { ?>
<li class="selected"><a href="<?php the_permalink() ?>">special page</a></li>
<?php } ?>
            
<?php elseif (isset($_GET['show'])) { ?>
<li><a href="<?php the_permalink() ?>">article</a></li>
<li class="selected"><a href="?show=comments">discussion</a></li>
<li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
<?php } ?>

<?php else { ?>
<li class="selected"><a href="<?php the_permalink() ?>">article</a></li>			
<li><a href="?show=comments">discussion</a></li>
<li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
<?php } ?>

Okay well I added the semi-colons but it's still giving me blank output. How much more information is needed? This is part of a template file for wordpress so I'm unsure as to how much exactly I need to show. I only showed the part I was having trouble with. Do you need to see the entire page that this is a part of?

	<?php 
echo $_GET['s'];
        if (isset($_GET['s'])) { ?>
<li class="selected"><a href="<?php the_permalink(); ?>">special page</a></li>
<?php } ?>
            
<?php elseif (isset($_GET['show'])) { ?>
<li><a href="<?php the_permalink(); ?>">article</a></li>
<li class="selected"><a href="?show=comments">discussion</a></li>
<li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
<?php } ?>

<?php else { ?>
<li class="selected"><a href="<?php the_permalink(); ?>">article</a></li>			
<li><a href="?show=comments">discussion</a></li>
<li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
<?php } ?>

 

Does that output anything? It might help to post the entire page - if its part of a template, because I don't see anything else wrong from a quick glance.

 

That didn't output anything either. I'll put together the different parts of the template and post it later. If it helps, it will output as long as I'm using plain if statements for each part, like this:

 

    	    //Section 1
    <?php if (!isset($_GET['show'])) { ?>
            <li class="selected"><a href="<?php the_permalink(); ?>">article</a></li>			
            <li><a href="?show=comments">discussion</a></li>
            <li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
            <?php } ?>

    	    //Section 2
            <?php if (isset($_GET['show']) && $_GET['show'] == "comments") { ?>
    <li><a href="<?php the_permalink(); ?>">article</a></li>
            <li class="selected"><a href="?show=comments">discussion</a></li>
            <li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
    	    <?php } ?>
            
    	    //Section 3
    <?php if (isset($_GET['s'])) { ?>
    <li class="selected"><a href="<?php the_permalink(); ?>">special page</a></li>
    	    <?php } ?>

 

 

But that doesn't do what I want. I want to choose among one of those three sections, but I can't figure out how to do it without using else. And as soon as I change any of them to else or try to use if/else statements, it spits out blank output.

Basically it works as long as I do this

 

    <?php if (isset($_GET['s'])) { ?>
    <li class="selected"><a href="<?php the_permalink(); ?>">special page</a></li>
    <?php } elseif (isset($_GET['show'])) { ?>
    <li><a href="<?php the_permalink(); ?>">article</a></li>
    <li class="selected"><a href="?show=comments">discussion</a></li>
    <li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
    <?php } else { ?>
    <li class="selected"><a href="<?php the_permalink(); ?>">article</a></li>            
    <li><a href="?show=comments">discussion</a></li>
    <li class="menu-break"><?php edit_post_link('edit this page'); ?></li>
    <?php } ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.