I have been reading on drupal.org for about 4 hours now, trying to figure out how to get a topic's forum name or id, and I still haven't found any solution. :'(

I just want to add a class to a div so I can theme the site based on which forum a topic is in.

So, conceptually something like this:

<div class="<?php print $terms ?>">


<div class="<?php $tid = $node->taxonomy_forums[$langcode][0]['tid']; print $tid; ?>">

Or something - I know that neither of those work.

I have also tried many of the solutions here:
and here:

I could really use some help here; I am really struggling to get this to work.


thermador’s picture

Issue summary:View changes

fixed formatting

thermador’s picture

Issue summary:View changes

fixed formatting

troky’s picture

what template (file) are you working on?

thermador’s picture

I was trying to put it in advanced-forum.naked.post.tpl.php, but I'm not even sure if that's right.

thermador’s picture

In case anyone else is trying to do this, I came up with a terrible, awful, ugly hack.

In: advanced-forum.naked.post.tpl.php where it says

just insert this before the last quotation mark, like so:

<div class="forum-post-content <?php
// strip the HTML tags
$forumname = strip_tags(render($content['taxonomy_forums']));
// remove spaces and replace with dashes
$forumnameclean = str_replace(' ', '-', $forumname);
// remove colons and replace with nothing
$forumnamecleaner = str_replace(':', '', $forumnameclean);
// remove non-breaking space characters and replace with dashes
$forumnamecleanest = str_replace('&nbsp;', '-', $forumnamecleaner);
print $forumnamecleanest;

Normally the following code would result in a formatted forum name, like "Forums: Product ABC Technical Support"

print render($content['taxonomy_forums']);

The code above strips the HTML and whittles it down to "Forums-Product-ABC-Technical-Support" which will work as a div class (yes it's ugly).

So in my HTML that is rendered in the browser, I get:

<div class="forum-post-content Forums-Product-ABC-Technical-Support">

This extra class allows me to set up my CSS do display things a bit differently in that forum (and ONLY in that forum) with CSS code like this:

DIV.Forums-Product-ABC-Technical-Support { font-family: 'Arial', sans; }

and let's say I have some fields hidden by default in the CSS (using display:none;) but I want to show them in this forum only - now I can do that:

DIV.Forums-Product-ABC-Technical-Support .field-name-field-software-version { display: block !important; }

I'm sure you can see how it would be immensely awesome if Advanced Forum automatically generated CSS classes with either the forum name or the taxonomy name or taxonomy id - basically ANY unique identifier so that people can use CSS to display a topic differently based on what forum it is in.

thermador’s picture

Issue summary:View changes

fixed formatting