Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
607 views
in Q2A Core by
In the categories pages there is always the Category Name (in the left side) and the number of questions associated with it (in the right side). When I click in the right side, it goes to the questions-page associated with that category.

How could I add this (ie a link to the questions-page associated with the category) also to the Category name in the left side?

1 Answer

+2 votes
by
selected by
 
Best answer

When you have sub-categories those category names become clickable and allow the user to navigate through the sub-categories. So replacing those links with links to the question lists will result in the user only being able to navigate through the level 1 categories.

If you're asking that question then it is likely that you are not even using sub-categories so you only see level 1 categories with no sub-categories which results in them being non-clickable as there is nothing to browser under them.

Taking that into account, it would make sense to add links to all the level 1 categories. Bear in mind this would not be valid the day you add a single subcategory as it will be unreachable.

You can change this behavior in your theme or create a plugin with a layer. In Q2A 1.7 this approach should do the trick. Just add this code to your theme:

public function initialize() {
    if ($this->template === 'categories' && isset($this->content['nav_list'])) {
        $categories = qa_db_single_select(qa_db_category_nav_selectspec('', false, false, true));
        foreach ($this->content['nav_list']['nav'] as &$category) {
            $catId = $category['categoryid'];
            $path = qa_path_html('questions/' . implode('/', array_reverse(explode('/', $categories[$catId]['backpath']))));
            $category['url'] = $path;
        }
    }
}

...