Top Left Text cha

Web & App Development

If you want a unique body class so that you can use different styles on different pages for styles that are typically common throughout the pages of Joomla. The uses for this are limitless.  I consider it a must have and include it on my template for every site I build.  Some templates may have this functionality included so you might want to check your template first.  I build my templates from scratch so I always need to do this.

Put this in the <head> section of your /template/index.php file:

    $app = JFactory::getApplication();
    $menu = $app->getMenu()->getActive();
    $pageclass = '';

    if (is_object($menu))
        $pageclass = $menu->params->get('pageclass_sfx');
    if ($pageclass != "homePage") {$otherclass = " interiorPage";}
    else {$otherclass = "";}

 Then replace the <body> tag of index.php with:

<body class="<?php echo $pageclass ? htmlspecialchars($pageclass) : 'default'; ?><?php echo $otherclass; ?>">

How to use:

Navigate to the menu item of the page you would like a unique style on.  

Under the 'page display' tab, enter the class you want to use in the field, 'Page Class'.  This comes with another advantageous element.  If you use the class, 'homePage' on your home page, it will also include the class, 'interiorPage' on all pages other than the home page.

Add comment

Security code

  • No comments found

Leave your comments

Post comment as a guest

Your comments are subjected to administrator's moderation.