Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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