Jump to content

Only show if var exists


OhTheNoes

Recommended Posts

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. :shy:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.