Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
6.0k views
in Q2A Core by
How can I display the category description when listing all questions from that category - I mean after clicking on a link to that category.

I would think this should be simple (and it makes great sense in my oppinion), but I haven't found it so far.

Thanks!
Q2A version: 1.6.3

2 Answers

+3 votes
by
selected by
 
Best answer

1. Create new plugin (e.g. qa-plugin/category-desc)

2. Upload qa-plugin.php under qa-plugin/category-desc

<?php
if (!defined('QA_VERSION')) {
  header('Location: ../../');
  exit;
}
qa_register_plugin_overrides('qa-cd-overrides.php');
3. Upload qa-cd-overrides.php under qa-plugin/category-desc
<?php
if (!defined('QA_VERSION')) {
  header('Location: ../../');
  exit;
}
function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle, $navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest, $pagelinkparams=null, $categoryparams=null, $dummy=null)
{
  $qa_content = qa_q_list_page_content_base($questions, $pagesize, $start, $count, $sometitle, $nonetitle, $navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest, $pagelinkparams, $categoryparams, $dummy);
  if(count($navcategories) && isset($categoryid)) {
    $catinfo = $navcategories[$categoryid];
    if(isset($catinfo['content']) && !empty($catinfo['content']))
      //$qa_content['title'] = $qa_content['title'].'<small style="display:block;margin-top:10px;">'.$catinfo['content'].'</small>'; // for Bootstrap
      $qa_content['title'] = $qa_content['title'].'<small style="font-size:65%;color:#777;display:block;margin-top:10px;">'.$catinfo['content'].'</small>'; // for pure HTML4 / HTML5
  }
  return $qa_content;
}
by
I have no idea what I did there, but it worked perfectly! Thank you so much! I really have to learn php...
by
Good day. By this method in the source code is obtained:

<title>"Title"+"description category"+" - "name q2a site"</title>

How to make:

<title>"Title"+" - "name q2a site"</title>
<description>"description category"</description>
+1 vote
by
hi,
its to easy to
1.
Add bellow  code in "qa_include/pages/default.php" BEFORE "return $qa_content";
<pre>
 if ($countslugs) {
                    $qa_content['categorydescription']=$categories[$categoryid]['content'];
                }
</pre>
2.
Call bellow Own Function for category Description in " main()"  after $this->page_title_error() in qa_include/qa_theme_base.php
<pre>
 if(isset($this->content['categorydescription'])){
                                $this->category_description();
                                }
</pre>
3. Describe function in same file qa_include/qa_theme_base.php after "public function page_title_error()"
<pre>
 public function category_description()
              {
                    $this->output('<div class="qa-q-list-item"><p>');
                      echo $this->content['categorydescription'];
                    $this->output('</p></div>');         
              }
</pre>
by
Modifying core is easy, but have the trouble to redo this every time core is updated. You can use this:
https://github.com/arjunsuresh/categorydescription
by
PS: The category description used is to be supplied separately as it supports HTML data as description.
by
edited by
Hello, it's not working correctly. After save description for category on site I have shown blank page, without any stored data. Can You check this, please? :)

Also, one more - I need to show category description on question page for category, as widget the best, not on top of question list as asked earlier :)
...