A plugin layer, such as the one you mentioned above, might be useful for that purpose:
- Create a plug-in
- Create a layer with the following code:
<?php
class qa_html_theme_layer extends qa_html_theme_base {
public function nav_main_sub()
{
if (qa_opt('nav_ask') && qa_user_maximum_permit_error('permit_post_q') != 'level') {
if ($this->template == 'tag') {
$tag = qa_request_part(1);
$this->content['navigation']['main']['ask']['url'] = qa_path_html('ask', array('tags' => $tag ));
} elseif ($this->template == 'question') {
// Rebuild 'Ask a Question' link.
$params = array();
if (qa_using_categories()) {
$categories = qa_db_select_with_pending(qa_db_category_nav_selectspec($this->content['q_view']['raw']['postid'], true, true, true));
$categoryids = array_keys(qa_category_path($categories, $this->content['q_view']['raw']['categoryid']));
$lastcategoryid = count($categoryids) > 0 ? end($categoryids) : null;
if (strlen($lastcategoryid))
$params['cat'] = $lastcategoryid;
}
if (qa_using_tags() && isset($this->content['q_view']['raw']['tags']))
$params['tags'] = $this->content['q_view']['raw']['tags'];
$this->content['navigation']['main']['ask']['url'] = qa_path_html('ask', !empty($params) ? $params : null);
}
}
parent::nav_main_sub();
}
public function form_fields($form, $columns) {
$tags = qa_html(trim(qa_get('tags')));
if ($tags && $this->template == 'ask')
$form['fields']['tags']['value'] = $tags;
parent::form_fields($form, $columns);
}
}
It has two features:
- When the user is on a tag page, clicking on "Ask a Question" will take the user to the "Ask" page with the tag field pre-filled.
- Posts can have a category and/or tags, so when the user is on a post, clicking on "Ask a Question" will take the user to the "Ask" page with both the category and the tag fields pre-filled.
If feature 2 is not needed, then remove the elseif block in the code. It would be like this:
<?php
class qa_html_theme_layer extends qa_html_theme_base {
public function nav_main_sub()
{
if (qa_opt('nav_ask') && qa_user_maximum_permit_error('permit_post_q') != 'level') {
if ($this->template == 'tag') {
$tag = qa_request_part(1);
$this->content['navigation']['main']['ask']['url'] = qa_path_html('ask', array('tags' => $tag ));
}
}
parent::nav_main_sub();
}
public function form_fields($form, $columns) {
$tags = qa_html(trim(qa_get('tags')));
if ($tags && $this->template == 'ask')
$form['fields']['tags']['value'] = $tags;
parent::form_fields($form, $columns);
}
}
If you don't know how to create a plugin, you might use qa-ask-with-tags-layer.php as a template for the code above.
I hope this answer is helpful. If you have any question, please add a comment below.
If you need specialized Question2Answer services and information you might have a look at the services page or send me a private message.
Have a good day.