WordPress.org

Ready to get started?Download WordPress

Forums

wp_loginout() active navigation state (6 posts)

  1. jiverson79
    Member
    Posted 2 years ago #

    I've created active states for my site's navigation which can be seen at here. It works just as I want it to. Only problem I'm having is getting an active state implemented for the wp_loginout() function. I understand there will need to be a couple different urls in the conditional statement, but can't figure out the syntax.

    Here's my code. Please help me out if you can. Thanks!

    <div id="menu">
    	<a href="http://eatpointshoot.com/" <?php if ( $_SERVER["REQUEST_URI"] == '/' ) echo " class='active' ";?>>recent</a>
    	<span class="space" style="margin-left:30px"></span>
    	<a href="http://eatpointshoot.com/?orderby=rand" <?php if ( $_SERVER["REQUEST_URI"] == '/?orderby=rand' ) echo " class='active' ";?>>random</a>
    	<span class="space" style="margin-left:30px"></span>
    	<?php wp_loginout()?>
    	<span class="space" style="margin-left:30px"></span>
    	<a href="http://eatpointshoot.com/default-form"<?php if ( $_SERVER["REQUEST_URI"] == '/default-form/' ) echo " class='active' ";?>>submit photos</a>
    </div>
  2. richarduk
    Member
    Posted 2 years ago #

    Is it single quotes?

  3. jiverson79
    Member
    Posted 2 years ago #

    I'm sorry, Richard, is what single quotes? see my code above. All of the links are formatted how I want them, but I just need to figure out how to translate the "if" statement to work with the login link which uses WordPress's wp_loginout() function.

    Thanks for looking into it!

  4. richarduk
    Member
    Posted 2 years ago #

    How about something vaguely like this?

    <?php $blah = wp_loginout( false); ?>
    (your url) <?php if ( $_SERVER["REQUEST_URI"] == '/' ) echo " class='active' ";?>

    http://codex.wordpress.org/Function_Reference/wp_loginout

  5. jiverson79
    Member
    Posted 2 years ago #

    Thanks again, Richard, but I tried this to no avail:

    <?php $userlogin = wp_loginout(); ?>
    
    <a href="$userlogin" <?php if ( $_SERVER["REQUEST_URI"] == '/login/') || ( $_SERVER["REQUEST_URI"] == '/login/?loggedout=true') || ( $_SERVER["REQUEST_URI"] == '/login/?action=register') echo " class='active' ";?>></a>

    I really think this is merely a php syntax issue. Any PHP wizards out there??

  6. richarduk
    Member
    Posted 2 years ago #

    I believe you have to put wp_loginout(false) - or it might be 'false' - to return it rather than echoing it.

Topic Closed

This topic has been closed to new replies.

About this Topic