Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
700 views
in Q2A Core by
I would like to be able to add some advertisement at the right of the logo and in the sidebar. Can you point me in the right direction?

1 Answer

+3 votes
by
edited by
For the sidebar, one simple way is to use the existing 'Custom HTML in sidebar' option in the 'Layout' section of the 'Admin' panel. Just stick your ad HTML in place of what's there, and it will be output on every page. If the background color is a problem, you can add </DIV><DIV> tags to close the DIV with the background styling, and re-open a new one.

However, to customize the page in ways that aren't directly supported by the 'Admin' panel, such as showing ads alongside the logo, you will need to create a custom theme as follows:

1. Make a copy of the Default theme directory in qa-theme and name it something like MyTheme.

2. Select your custom theme in the 'Admin' panel, 'Layout' sub-panel.

3. Create a file in your custom theme directory called qa-theme.php, which contains the following:

<?php

    class qa_html_theme extends qa_html_theme_base
    {
        function logo()
        {
            qa_html_theme_base::logo();
            $this->output('YOUR_HTML_HERE');
        }
    }

?>


4. Modify the YOUR_HTML_HERE in the code to show the ad content next to the logo, as appropriate for your needs. Instead of $this->output() you can also just use PHP's echo or print functions.

What's happening here is that your theme is defining a function which overrides the default behavior for the logo. Your version of the function first calls the original version using :: notation, then it does it own thing.

If you want to use a unified method for ads in both places, you could also use the above technique to override the default sidebar() function:

<?php

    class qa_html_theme extends qa_html_theme_base
    {
        function logo()
        {
            qa_html_theme_base::logo();
            $this->output('YOUR_HTML_HERE');
        }

        function sidebar()
        {
            qa_html_theme_base::sidebar();
            $this->output('YOUR_HTML_HERE');
        }
    }
    
?>
by
There is now proper documentation on the main site about creating themes: http://www.question2answer.org/advanced.php#theme
by
Great post gidgreen. It works for me
...