OhTheNoes Posted March 27, 2011 Share Posted March 27, 2011 I apologize in advance for any misuse of terminology. I find that I am rather ignorant in such things. I'm working on a WordPress theme. Specifically on the part that shows the "next: link-to-next-post" and "previous: link-to-prev-post" links. Here is the code that I have: <?php $nextvar=next_post_link('%link'); $prevvar=previous_post_link('%link'); ?> <?php if (isset($nextvar)) { ?> <h3>Next</h3> <p><?php next_post_link('%link'); ?></p> <? } ?> <?php if (isset($prevvar)) { ?> <h3>Previous</h3> <p><?php previous_post_link('%link'); ?></p> <? } ?> The first part intends to check if the links exist. And this works fine. However, the only output I'm getting are the values of $nextvar and $prevvar. The headers are nonexistent. What's wrong? Any help is much appreciated, and I thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/231888-only-show-if-var-exists/ Share on other sites More sharing options...
denno020 Posted March 28, 2011 Share Posted March 28, 2011 Your code works for me, but only if I put the full php tag '<?php' not just '<?'.. I didn't use the next_post_link() functions, I just made each of those variables equal to a string, so as to force the set or unset state. And echoed accordingly.. So just try changing the php tags before the ending curley braces. Denno Quote Link to comment https://forums.phpfreaks.com/topic/231888-only-show-if-var-exists/#findComment-1193117 Share on other sites More sharing options...
OhTheNoes Posted March 28, 2011 Author Share Posted March 28, 2011 Oh shoot, I can't believe I missed that. Shouldn't have been working at 5am really =/ Thank you, Denno! Quote Link to comment https://forums.phpfreaks.com/topic/231888-only-show-if-var-exists/#findComment-1193129 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.