title: Add page class suffix based on active item in Joomla 3.1.1
body: <p>I want to add a page class to my body tag (or a div) based on the page I am viewing. I found <a href="http://docs.joomla.org/Using_the_Page_Class_Suffix_in_Template_Code" rel="nofollow">a tutorial</a> but it's not working 100%, it adds id="default" to every page. I need each page to generate a special class or id. </p>
  
  <p>This is what I have so far, plugged into index.php of my template:</p>
  
  <pre><code>&lt;?php
    $itemid = JRequest::getVar('Itemid');
    $menu = &amp;JSite::getMenu();
    $active = $menu-&gt;getItem($itemid);
    $params = $menu-&gt;getParams( $active-&gt;id );
    $pageclass = $params-&gt;get( 'pageclass_sfx' );
  ?&gt;
  &lt;/head&gt;
  &lt;body id="&lt;?php echo $pageclass ? htmlspecialchars($pageclass) : 'default'; ?&gt;"&gt;
  </code></pre>
  
  <p>PS. My search engine friendly URLs aren't working so I had to turn them off.</p>