Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
2.8k views
in Q2A Core by
edited by

I would like to now if I can access the TAGS of the question directly from a widget / layer.

What is the code for getting the tags in an array?

Can I get them without an extra database query?

--

Edit: I found function post_tag_list in qa-theme-base.php. There tags get output like that:

            foreach ($post['q_tags'] as $tag)
                $this->post_tag_item($tag, $class);

Can I access $post['q_tags'] without any "preparation" from the widget?

--

2nd part of the question: How to access Tags from Advanced Theme?

 

2 Answers

+3 votes
by
selected by
 
Best answer

Look at $qa_content['q_view']['raw'] in your output_widget(...) function.

by
Sorry, I was not specific enough. I meant a plugin layer.

To output some html below the question I am overwriting like that:
class qa_html_theme_layer extends qa_html_theme_base {
  function q_view_clear() {
    qa_html_theme_base::q_view_clear();
    $this->output('<div id="suggestBox">
        <a href="http://www.echteinfach.tv/mathe-videos?s=">Videos to your question</a></div>');
} }

I want to read the tags from within the layer to be able to use one of the tags (after some internal matching) for the anchor's URL: ?s=TAG
by
A layer is just a subclass of the Q2A theme base class. So you would use this instead of what I wrote above:

$this->content['q_view']['raw']
by
edited by
Alright, here we go:
$this->content['q_view']['raw']['tags'] // returns a string of tags tag1,tag2,tag3

:o) perfect!
by
BTW there should be a function available to change that list to an array if you need that, I think it's something like "tagstring_to_words". Check in the string-util file.
by
I am using: $tagsArray = explode(',',$tags);
+1 vote
by

Alright, here we go:

$this->content['q_view']['raw']['tags'] // returns a string of tags tag1,tag2,tag3
$tagsArray = explode(',',$tags);

:o) perfect!

by
Can you explain this in layman language, so that we can show recent tags in sidebar?
...