Thanks, Kafkaesqui, I wish my search would have found that as quickly as yours did (of course you wrote it, too 🙂 ). Can I put that between li tags in a ul list?
Sure can:
<?php
global $user_login;
get_currentuserinfo();
if ($user_login) :
?>
<ul>
<li><a href="/wp-admin/post.php">New Post</a></li>
</ul>
<?php endif; ?>
I’m thinking of the “log in”/”Register” ul list, adding this as a third item that would only appear when logged in. In such a case, should I put the whole code within the li tags?
Such as:
<li><?php global $user_login; get_currentuserinfo(); if ($user_login) : ?><a href="/wp-admin/post.php">New Post</a><?php endif; ?></li>
YES!
I tried my version and, after removing the leading “/” from the “/wp-admin/post.php” link it works!
Thank you Kafkaesqui!
“Such as: …”
It’d work that way, but you’d be left with an empty list tag when logged out. So do it as I have above, but remove the <ul>
and </ul>
tags.
And you’re welcome. ;)
OK, so put the user info code between the list items within the existing ul, right? If I read it right, doing it that way would eliminate the empty li tag.
And it seems to work just fine.
Since I am a php novice I have a question:
Would it work if I were to replace
<li id="other"><?php _e('Other:'); ?>
<ul>
<li><a href="<?php echo get_settings('siteurl'); ?>/wp-login.php"><?php _e('Login'); ?></a></li>
<li><a href="<?php echo get_settings('siteurl'); ?>/wp-register.php"><?php _e('Register'); ?></a></li>
</ul>
</li>
with
<li id="other"><?php _e('Other:'); ?>
<ul>
<?php
global $user_login;
get_currentuserinfo();
if ($user_login) :
?>
<li><a href="<?php echo get_settings('siteurl')
?>/wp-login.php?action=logout" title="<?php _e('Log out of this account') ?>"><?php printf(__('Logout (%s)'), stripslashes($user_nickname)) ?></a></li>
<li><a href="wp-admin/post.php">New Post</a></li>
<?php else ?>
<li><a href="<?php echo get_settings('siteurl'); ?>/wp-login.php"><?php _e('Login'); ?></a></li>
<li><a href="<?php echo get_settings('siteurl'); ?>/wp-register.php"><?php _e('Register'); ?></a></li>
<?php endif; ?>
</ul>
</li>
in index.php?
It should work fine if change your ‘else’ line to:
<?php else : ?>