Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.9k views
in Themes by
How can I edit sidebar custom HTML to be able to include a php file inside it?

I found this question that is similiar to mine but I can't find the function responsible for custom html sidebar.

http://www.question2answer.org/qa/35707/how-to-include-php-on-every-page

Thanks in advance guys
by
I don't quite get what you're trying to do. What do you mean by "include a php file inside it"?
by
I wanted to include some php code in sidebar.
I managed to do it by editing and renaming adsense widget.
by
Hey how did you do that?
Would you please explain how? in detail?
I am using adsense widget for adsense?
Can I use that again? If yes how?

Thanks

1 Answer

0 votes
by

Is your hope this?

In case of using admin panel (If there is little processing...)

  1. Make new plugin
  2. Override qa_content_prepare() function of qa-include/qa-page.php
  3. Modify L497 in your qa_content_prepare() function.
    e.g.
    //'sidebar' => qa_opt('show_custom_sidebar') ? qa_opt('custom_sidebar') : null,
    'sidebar' => qa_opt('show_custom_sidebar') ? eval(qa_opt('custom_sidebar')) : null,
  4. Login as admin
  5. Input PHP code in "Admin" > "Layout" > "Custom HTML in sidebar box on every page:"
    e,g,
    $ret = 'Hello World!';
    return $ret;

In case of not using admin panel (If there is many processing...)

  1. Make new plugin
  2. Override qa_content_prepare() function of qa-include/qa-page.php
  3. Make new qa-my-sidebar.php on qa-include directory
    e.g. (Don't add "<?php")
    if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
      return '';
    }
    $ret = 'Hello World';
    return $ret;
  4. Modify L497 in your qa_content_prepare() function.
    e.g.
    //'sidebar' => qa_opt('show_custom_sidebar') ? qa_opt('custom_sidebar') : null,
    'sidebar' => qa_opt('show_custom_sidebar') ? eval(file_get_contents(QA_INCLUDE_DIR.'qa-my-sidebar.php')) : null,

Reference:
http://php.net/manual/en/function.eval.php

Caution:
This suggestion is for seniors who were familiar with PHP. This code is risky. If you do wrong operation, your site may not move at all. If it happen, it will be necessary to repair specific record of qa_options table in your database directly OR put back source file. Anyway, be careful.

There may be other methods.

...