Skip to main content
Feb 24, 2019

Question2Answer script doesn't have theme system consisted of HTML files, but all HTML outputs are performed though PHP code. For beginners it is not quite easy to understand how to make even a simple changes, so we're going to explain how to insert custom HTML code (e.g. Adsense).

Question2Answer theme logic explanation

Question2Answer script doesn't have a "common" template system made of HTML files, but rather outputs HTML code directly via PHP functions.

Every logic has its own function that outputs HTML code. For example, function q_view() displays question.

How to override a function

You can either to create a custom theme or to modify existing one. We suggest creating your own theme because changes will be replaced during update, but for purpose of this article we're going to describe changing Default theme.

1) Create file qa-theme.php in folder qa-themes/Default and add the following code:

<?php
class qa_html_theme extends qa_html_theme_base {
 
}

2) Copy appropriate function from file qa-include/qa-theme-base.php into qa-theme.php

3) Add your own HTML or Adsense code inside $this->output() method. For example, if you want to add the code above content, copy main function into qa-theme.php file (into the theme class) and make changes

function main()
  {
    $content=$this->content;
 
    $this->output('<DIV CLASS="qa-main'.(@$this->content['hidden'] ? ' qa-main-hidden' : '').'">');
     
    // CUSTOM CODE
    $this->output('<div style="text-align:center; padding-top: 5px;">');
    $this->output('YOUR ADSENSE CODE HERE');
    $this->output('</div>');
    // /CUSTOM CODE
     
    $this->widgets('main', 'top');
     
    $this->page_title_error();   
     
    $this->widgets('main', 'high');
 
    /*if (isset($content['main_form_tags']))
      $this->output('<FORM '.$content['main_form_tags'].'>');*/
       
    $this->main_parts($content);
   
    /*if (isset($content['main_form_tags']))
      $this->output('</FORM>');*/
       
    $this->widgets('main', 'low');
 
    $this->page_links();
    $this->suggest_next();
     
    $this->widgets('main', 'bottom');
 
    $this->output('</DIV> <!-- END qa-main -->', '');
  }

4) Refresh page and you'll see new part over content on all pages