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

Show a message just to unregistered or anonymous users

+1 vote
asked Jun 9, 2014 in Q2A Core by distante
edited Jun 9, 2014 by distante

I have this site where I let anonymous questions to be posted, but I realized that some users don't really want to post as an anon but just don't know they are doing it.

Is there a way to show a message in the ask page ( mysite.com/ask ) that just for unregistered or anon users? so I can put a warning like "You are asking a question as an anon, if you want, you can register here"



Using the idea given by q2apro.com I find that I need to add this in the place where I want the message to appear (in my case below $this->nav_main_sub(); inside qa-theme.php of the snow theme)

if (!qa_is_logged_in()) {
$this->output('MY MESSAGE');}
But I don't know how to check if I'm in the ask page or don't.
Q2A version: 1.6.3

2 Answers

0 votes
answered Jun 9, 2014 by distante
Best answer

So, I did some Research in the function and themes documentation, and got this:


It is just showed in the ask page using this code:

if (!qa_is_logged_in() and $this->template=='ask'){
$this->output('<br /><div class="qa-error"> Warning!! <br />MY MESSAGE</div>');
rigth after:
Hope it helps to somebody else.
Big thanks to q2apro.com who point me in the right direction.
0 votes
answered Jun 9, 2014 by q2apro
edited Jun 9, 2014 by q2apro

Good idea.

Easy solution: When you use a captach for only anonymous guests that would be a "message" already. You could add a line to the captcha plugin "You are posting *anonymously*, please fill out the captcha".


Tutorial for showing an extra message:

1. open your qa-theme.php

2. add this code overriding the main() function:

        function main() {
             if(!qa_is_logged_in()) {
                 $this->output('<p>You are posting anonymously!</p>');
            // default method call

3. upload the qa-theme.php to your server

commented Jun 9, 2014 by distante
edited Jun 9, 2014 by distante
Thanks for your reply, I'm using the "snow theme" that comes with Q2A 1.6.3 and there's no `function main()`

I edited the last part of the question.
commented Jun 10, 2014 by q2apro
you just "add this code" to the file qa-theme.php