Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.4k views
in Q2A Core by
I'm not a developer but I'm trudging along and learning a lot about php and Q2A and I'm excited about what I've been able to do.

One thing I got stuck on was how to display some text next to the "login" and "register" buttons. The text should only appear when a user is not logged in.

Any help or guidance would be great!
Q2A version: Latest

1 Answer

+2 votes
by
selected by
 
Best answer

Add this code to your qa-theme.php :

        function logged_in()
        {
            if (isset($this->content['loggedin'])) echo "welcome and";
            $this->output_split(@$this->content['loggedin'], 'qa-logged-in', 'DIV');
        }

 

when user is loged in it will write welcome and Hello User.

by
Thanks for the reply towhid. I'm looking for text to appear when a user is not logged in though. Text to go next to the "Register" button for a new user to read.
by
change the IF statement:

function logged_in()
        {
            if (!isset($this->content['loggedin'])) echo "welcome and";
            $this->output_split(@$this->content['loggedin'], 'qa-logged-in', 'DIV');
        }

this will work
by
I'm not a developer. I understand what an IF statement is and can understand code enough to move it around or do small edits, but as far as editing this code, I'm at a loss as to how to make this work.

Thanks anyways.
by
1) function logged_in prints the user navigation links.
2) $this->content['loggedin'] is the array responsible for printing user navigation when user is logged in.
3)  if (!isset($this->content['loggedin'])) means if "content['loggedin']" is not(!) set(isset function) then print the value "Welcome and" or anything else.

now what you should do is explained here:
http://www.question2answer.org/themes.php

create a file called qa-theme.php and copy it inside your theme directory.
and add this text to it and save:
class qa_html_theme extends qa_html_theme_base
{
    function logged_in()
        {
            if (!isset($this->content['loggedin'])) echo "welcome and";
            $this->output_split(@$this->content['loggedin'], 'qa-logged-in', 'DIV');
        }
}
any problem: read the article in above link!
by
Thanks again for your time and patience. It looks like the ! was missing before the (isset so I was only getting the message when the user was logged in.

Works great now, thanks!
...