Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
772 views
in Q2A Core by
i want to change several widths of some tables, how can I get just one specific table like for example the one on the login form ?

1 Answer

+1 vote
by
 
Best answer

There isn't currently a CSS way to differentiate between different pages, but it's a really good idea. For now you could add the body_tags() function in your qa-theme.php file (assuming you're using an advanced theme) to output the value of $this->template as a CSS class, like so:

function body_tags()
{
  echo 'CLASS="qa-body-'.$this->template.'"';
}

Then you can use a nested CSS rule in qa-styles.css to change the look of an element on that particular page only, e.g. for the login form:

.qa-body-login .qa-form-tall-table { ... }

by
edited by
What an excellent solution !!!


So now I can style each (template) page differently as far as necessary. I required this as I am playing around with liquid width, and the forms on login and register shouldn´t stretch to the full width...


If I understand it right, body-tags generates a class for the single (template) page.

Would it then as well be possible to generate this way as well classes for each category ? For example to use regional images, or game backgrounds or similar through css?

Amazing possibilities with this "simple" change in qa-theme.php !

Thank You, I am still really impressed of Your script ! You have to know that we "non-programmers" allways have to fight with free or even paid scripts and often never find a solution for a single problem...

Edit: Refering to added pages would be great as well..
Edit2: This works allready, found it as .qa-body-custom
by
edited by
Ok, I tried my luck and it seems to work:

function body_tags()
{
$actualurl = $_SERVER['REQUEST_URI'];  // requesting url
$actualurl = strtr($actualurl, "/", "-");  // changing slash into -
$start = strpos($actualurl, '?'); // searching for parameter position
if($start==0){ // if no parameter nothing
}
else{
$actualurl = substr($actualurl, 0,$start); // else taking string until parameterposition
}

if (substr_count($actualurl,"-user-")>0){
  $actualurl="-user";}
else{
}  // to have the user pages all under one tag

echo 'CLASS="qa-body'.$actualurl.'"';

} // abstract method

This seems to work, but is this ok with the script ?


There were other things like
 echo parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
and
$_SERVER['REQUEST_URL']
but I did not make them work..

It would give out a body class for every single page including categories.

Please let me know if it is not possible or if I missed something !

I am still thrilled by the amazing possibilities this would open for css..

Thanks monk333
by
One good (but hacky) way of getting the ID of the current category is to look at the value of the cat parameter at the end of the 'Ask' menu link:

So the expansion of my code above could be:

function body_tags()
{
    echo 'CLASS="qa-body-'.$this->template;
           
    if (preg_match('/cat=([0-9]+)$/', $this->content['navigation']['main']['ask']['url'], $matches))
        echo ' qa-body-category-'.$matches[1];
               
    echo '"';
}

The advantage of this is that it will also work for question pages.

I have made a note to integrate this type of CSS page verification into the next version, since it's very easy to do, and can be very helpful.
by
Great, this was what I couldn´t resolve. This way it would be possible to have lets say same background for one category and all its questions.

Thank You for putting it on the roadmap, will help a lot.

monk333
...