Topic: Using current topic id to apply dynamic CSS class
On my site, I have a two column layout with recent topics displayed in a sidebar using extern.php. I'd like to use CSS to change the colour of the sidebar link if that topic is being displayed.
I've managed to get a class into the list output from extern.php by changing:
echo '<li><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$subject_truncated.'</a></li>'."\n";
to:
echo '<li class="pun_'.$cur_topic['id'].'"><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$subject_truncated.'</a></li>'."\n";
(note I've added the following inside the <li> tag:
class="pun_'.$cur_topic['id'].'"
I've now tried adding the following CSS to the <head> of header.php:
<?php
echo '<style type="text/css"> ';
echo 'ul li. pun_'.$cur_topic['id'].' a:link,';
echo 'ul li. pun_'.$cur_topic['id'].' a:hover,';
echo 'ul li. pun_'.$cur_topic['id'].' a:active,';
echo 'ul li. pun_'.$cur_topic['id'].' a:visited,';
echo '{color: #ccc; text-decoration: none;} ';
echo '</style>';
?>
But I don't get a value for $cur_topic[id]. I think that I need to get the topic id into header.php but I don't know how.
I'm pretty sure it should be easy to give $cur_topic[id] the id of the current topic but I'm at the limit of my (very limited) php/sql knowledge here.
Can anyone help me out please?