Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 ?>">
or
<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:
https://drupal.org/node/909968
and here:
https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/funct...
I could really use some help here; I am really struggling to get this to work.
Comments
Comment #0.0
thermador CreditAttribution: thermador commentedfixed formatting
Comment #0.1
thermador CreditAttribution: thermador commentedfixed formatting
Comment #1
troky CreditAttribution: troky commentedwhat template (file) are you working on?
Comment #2
thermador CreditAttribution: thermador commentedI was trying to put it in advanced-forum.naked.post.tpl.php, but I'm not even sure if that's right.
Comment #3
thermador CreditAttribution: thermador commentedIn 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
Normally the following code would result in a formatted forum name, like "Forums: Product ABC Technical Support"
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:
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:
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:
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.
Comment #3.0
thermador CreditAttribution: thermador commentedfixed formatting