Hi Hella,
It works in that way because they share the same page template: 'qa'. I can also reproduce this behavior in the following pages:
- 'Recent questions and answers', which also includes the pages shown after clicking on category links in this page
- 'Question lists', and pages shown after clicking on category links
- 'Recent activity', and pages shown after clicking on category links
- 'Ask a question', which is rendered differently depending on whether the 'Ask a Question' button is clicked while visiting a category listing or not
Now, this answer will work for you if:
- You don't mind modifying Q2A in and of itself (or using an plugin override)
- It's possible to tweak the widget's allow_template method
First, add the following code:
global $qa_is_category_page;
$qa_is_category_page = !empty($categoryids);
to function 'qa_content_prepare', in qa-include/app/page.php right after line 476.
Second, use this variable in the method allow_template. Let's say the widget that needs to be shown on homepage is the Category widget. Its method allow_template looks like this:
public function allow_template($template)
{
return true;
}
but now the variable '$qa_is_category_page' is available in the function above and it's possible to check if the page being rendered is a category page or not:
public function allow_template($template)
{
// return true;
global $qa_is_category_page;
return $template == 'categories' || !$qa_is_category_page;
}
You can make other widget available on homepage (but not in category pages) by following similar steps.
I hope this answer does the trick :-)