Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Q2A Core by
I want to use first tag of question in page-title in question page How can I do that?
Q2A version: 1.5.3

2 Answers

+2 votes

There may be other or simple way to make it works but here I write code for you and it's tested. Just place below two functions into your theme files and you done.


function get_first_tag()
// to check whether this is question page
if($this->template == 'question') {
//get current url for postid
$myurlpieces = explode("/", $myurl);
//run query to get post tags
$query = "SELECT tags FROM ^posts WHERE postid=$pid"; //run query
$tags = qa_db_query_sub($query);
//loop through
while($tag=qa_db_read_one_assoc($tags, true)){
$tag = explode(',', $tag['tags']); //convert tag items into array
return array_shift($tag) . ' | '; // this will get first tag from array
function head_title()
$pagetitle=strlen($this->request) ? strip_tags(@$this->content['title']) : '';
$headtitle=(strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title'];
// add tags function here
$this->output('<TITLE>'. $this->get_first_tag() . $headtitle.'</TITLE>');
You also can use - return $tag[0] . ' | ';  instead of - return array_shift($tag) . ' | '; up to you,
Thanks Jatin.soni for your support ;)  in fact i have placed the two functions within the class that extends qa_html_theme_base but nothing happend do i miss something ?
0 votes

i managed to do it by simply overriding the post_tag_list  function by the following :

function post_tag_list($post, $class)
$this->output('<ul class="'.$class.'-tag-list">');
$this->post_tag_item($taghtml, $class);
The tip is to remove the loop that goes through all tags and return only the first value of tags array .

but i still have a hanging issue how to apply this change only to the question list page ?

Sorry to being delay.. That's good you have solve the issue..