yotamono Posted January 22, 2009 Share Posted January 22, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/ Share on other sites More sharing options...
haku Posted January 22, 2009 Share Posted January 22, 2009 Not such a straightforward question. That's like giving a picture of a car and saying 'why doesn't this start?'. Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742833 Share on other sites More sharing options...
Philip Posted January 22, 2009 Share Posted January 22, 2009 You're forgetting the semicolon on the end of the function call. <?php the_permalink() ?> should be: <?php the_permalink(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742834 Share on other sites More sharing options...
yotamono Posted January 22, 2009 Author Share Posted January 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742836 Share on other sites More sharing options...
Philip Posted January 22, 2009 Share Posted January 22, 2009 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742838 Share on other sites More sharing options...
yotamono Posted January 22, 2009 Author Share Posted January 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742844 Share on other sites More sharing options...
yotamono Posted January 22, 2009 Author Share Posted January 22, 2009 Okay I've got this resolved. Seems like putting a closing ?> tag after the end of an if/else block and then using another <?php before the following elseif/else causes problems because of the whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742848 Share on other sites More sharing options...
yotamono Posted January 22, 2009 Author Share Posted January 22, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141878-solved-if-else-statement-using-isset-creates-blank-output/#findComment-742850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.