Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
  • Register
Welcome to the Q&A for Question2Answer.

If you have questions about the platform, click here to ask and please use English.

If you just want to try Q2A, please use the demo, which also grants admin access.

Apr 29: Q2A 1.5.2

Conditional Login/Logout Link

0 votes
I've been trying to work out the code for a link to display in the footer of my site such that it brings the user to the login page only if the user is not logged in. Once he/she is logged in, that same link will logout the user instead. I have Q2A linked to my WP install, so I was thinking along the lines of the wp_loginout function, but my PHP-fu isn't quite good, so any help you guys might be able to offer me would be much appreciated.
Q2A version: 1.4.3
asked Nov 27, 2011 in Q2A Core by anonymous

1 Answer

0 votes

There may be a more direct way, but I would use something like:

if(qa_logged_in_userid()) {

    // show log out

}

else {

    // show login

}

answered Nov 27, 2011 by NoahY
Thanks for the advice. I've got something like this:

        <? php
          if (qa_get_logged_in_userid()) {
             echo '<p>Log Out</p>';
            }
          else {
              echo '<p>Log In</p>';
          }
        ?>

Inserted into the header under "Layout". Seems however, that the escape from HTML to PHP doesn't work, and I end up with the following output verbatim:

Log Out

'; } else { print '

Log In
'; } ?>

What am I not doing right?
I doubt those boxes allow php code (you need to use <?php, not <? php, but it probably doesn't work anyway.  Only way to go is to use a custom layer, or edit your theme's qa-theme.php.  See:

http://www.question2answer.org/layers.php