Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
851 views
in Q2A Core by
I want to include a category image at each question.

Which file do I need to edit to achieve this?

qa-app-format.php I guess?
by
/editted nevermind....

2 Answers

0 votes
by
 
Best answer

Well, I am trying to do this by myself.

I found this function:

        function post_meta_where($post, $class)
        {
            $this->output_split(@$post['where'], $class.'-where');
        }

to return the categorylink.

But I only want the raw category name, not also the html.

How can I get that?

If I have the raw category name, I can assign images to it.

by
I have tried strip_tags() to strip all the html/php code so that only the raw categoryname is the leftover, but strip_tags() doesn't do anything.

WTF :-D
by
The raw category name is in $post['raw']['categoryname'] - $post['where'] is actually an array, so strip_tags() won't work on it.
0 votes
by
edited by

I finally got it working using the following code.

Mind the cat_image function I have added to q_item_stats... the rest is trivial.


________________________________

function q_item_stats($question){
        $this->output('<DIV CLASS="qa-q-item-stats">');
        $this->cat_image($question);
        $this->voting($question);
        $this->a_count($question);
        $this->output('</DIV>');
}

function cat_image($post) {
      $raw_catname = $post['raw']['categoryname'];

      if ($raw_catname=='Sports') {
      echo '<img alt="Category image sports" src="http://www.rtvemmen.nl/useruploads/images/avatars/sport_algemeen.jpg"/>';
      }

      if ($raw_catname=='Politics') {
      echo '<img alt="Category image politics" src="http://prospero.murdoch.edu.au:90/screens/images/politicians.jpg"/>';
      }

}

________________________________

You can add more category images by simply copy-pasting the if statements in the last section of function output_array_cat.

...