Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+9 votes
5.8k views
in Q2A Core by
I want to perform below same function in V1.2.
http://www.question2answer.org/qa/363/how-can-i-add-tag-to-sidebar
qa-page-home.php of V1.2 is many changed. If possible, teach us modification for V1.2.
Thanks in advance.

2 Answers

+5 votes
by
It's a similar idea, but the code is structured a little differently, so here goes...

Start by modifying function qa_home_load_ifcategory(...) in qa-page-home.php:

1. Add $populartags to the global list at the start of the function.

2. Change the code below:

        @list($questions1, $questions2, $questions3, $count, $categories, $categoryid, $custompage)=qa_db_select_with_pending($qa_db,
            $questionselectspec1,
            $questionselectspec2,
            $questionselectspec3,
            (isset($cachecountoption) && !isset($categoryslug)) ? qa_db_options_cache_selectspec($cachecountoption) : null,
            qa_db_categories_selectspec(),
            isset($categoryslug) ? qa_db_slug_to_category_id_selectspec($categoryslug) : null,
            $pageselectspec
        );

... to ...

        @list($questions1, $questions2, $questions3, $count, $categories, $categoryid, $custompage, $populartags)=qa_db_select_with_pending($qa_db,
            $questionselectspec1,
            $questionselectspec2,
            $questionselectspec3,
            (isset($cachecountoption) && !isset($categoryslug)) ? qa_db_options_cache_selectspec($cachecountoption) : null,
            qa_db_categories_selectspec(),
            isset($categoryslug) ? qa_db_slug_to_category_id_selectspec($categoryslug) : null,
            $pageselectspec,
            qa_db_popular_tags_selectspec(0)
        );

[All that changed is that $populartags was added to the end of the list(...) and qa_db_popular_tags_selectspec(0) was added at the end of the parameters to the qa_db_select_with_pending(...) call.]

3. Lower down in the same file, after qa_content_prepare(true, $categoryid); add the $populartags variable to $qa_content as follows:

$qa_content['populartags']=@$populartags;

4. Create a custom theme (see Advanced page on main site) and override the sidebar() function. Make sure your theme's sidebar() function calls the default one first via qa_html_theme_base::sidebar() otherwise your custom sidebar box will disappear. Then your function can do something with $this->content['populartags'], after checking isset($this->content['populartags']) since not every page will have it defined. To start with you can print_r($this->content['populartags']) to get an idea of what it contains. You can use qa_tag_html() to convert a tag to the standard HTML representation.
by
Out of my view it is easier to add all the funtions from qa-theme-base.php
beginning with:


function doctype()

more or less at the top of the file
until
the last one

function c_item_clear()
        {
            $this->output(
                '<DIV CLASS="qa-c-item-clear">',
                '</DIV>'
            );
        }

This is easier if You want to make more chnages.

Once ready, You can add after the

function sidebar()
{
.... means the whole sidebar function
}
by
The problem with adding all the functions is your theme is much more likely to have problems with a future version of Q2A. My recommendation is to add only those functions to your qa-theme.php file which you need to override.
by
edited by
Thanxs for summing up to monk333!
just a little typo: the href for "All Tags" is missing a dot "."
it must be:
echo "<li class=\"qa-sidebar-poptags-li\"><a class=\"qa-sidebar-poptags-link-all\" href=\"./tags/\">All Tags</a></li>";

****href=\"./tags/\****   instead of
****href=\"/tags/\****

and it only works for me without the "$count" in qa-page.home.php:
that means:
    global $categoryslug, $questions, $categories, ****
and delete the line:

            (isset($cachecountoption) && !isset($categoryslug)) ? qa_db_options_cache_selectspec($cachecountoption) : null,

after "    $questionselectspec4,"
by
it seems that version 1.5.x has the tag widget which can solve this question :D
0 votes
by
Using the Code on this page puts the tags on the questions page, but how do we get it on all pages?
...