Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
660 views
in Themes by
q2a provides specific  css selector tied to body tags on every page so that  on users page we have  : "qa-template-users" selector, on question page we have : "qa-template-question". this helps to acheive better contextual formatting. but why on custom pages there is no specification. all custom pages have the selector : " qa-template-custom" it would be better if we have "qa-template-{page-title}". is it possible ? how could this be done ?

Thank you.
Q2A version: 1.6.2
by
edited by
+1 This is valid point. It should be dynamic as per the page name instead of 'custom'
by
+1 should be core. Taking the URL of the page and using it as selector.
by
@q2apro.com The code I have added below can be the hook. Since I checked in some other files as well but this is the only method which generates the class for the body tag.

However, defining custom class is possible for the page module by using qa_set_template($template);

Let's see what Scott syas, I may add pull request for this hook. If he things this is the better way than it might be within the core in next release...
by
Yes, this is actually a good idea! However there are a few things to consider:

- We should keep 'qa-template-custom' in there because people may want to target all custom pages. Actually they may be doing this already and we don't want to break backwards-compatibility where possible. So it would be "qa-template-custom qa-template-mytitle"
- I don't think we can base it purely on the URL. For my edit history plugin, the URLs are like `revisions/3` or `revisions/9`. But the class here should be "qa-template-revisions"

Edit: actually plugins currently use "qa-template-plugin" and not custom. But the same should apply, the above example should have classes "qa-template-plugin qa-template-revisions". For plugins this may be able to come from the suggest_request function.
by
@Scott,

Agree and all your concerning points are valid. Let me try to change the second code (adding class) using suggest_request sanction. Than I may send you pull request. If need any help, I will post on this question.

1 Answer

+1 vote
by

Okay here is the hook. Add below code to your theme file or plugin layer.

Find code on Gist

Or use below





	

// To replace qa-template-custom to qa-template-my-page
function body_tags()
{
 
$class = (($this->template == 'custom') ? 'qa-template-' . qa_request() : 'qa-template-' . qa_html($this->template));
 
if (isset($this->content['categoryids']))
foreach ($this->content['categoryids'] as $categoryid)
$class.=' qa-category-' . qa_html($categoryid);
 
$this->output('class="' . $class . ' qa-body-js-off"');
}
 
No more characters allowed here so better you check on GIST once https://gist.github.com/q2amarket/9680759

 

...