We help IT Professionals succeed at work.

Joomla Body ID Tag Using Menu Item Alias

smfmetro10 used Ask the Experts™

I am trying to create unique body tags for each of my pages in my custom template that I created for Joomla.  In my custom template index.php file, I used the code:
$menu = &JSite::getMenu();
$active = $menu->getActive();
<body id="page_<?php print $active->alias; ?>">

Open in new window

in place of the <body> tag.  

In my Joomla admin panel, I go to Menus -> Menu Manager, and click "Menu Items" in the Main Menu row.  I have two items in there: Home (was in there already)  and Courses.  When I click on "Courses," it goes to the editing screen, and the Alias says "courses."  (and it refers to an article "Courses" in the parameters area.

So theoretically, my body tag should say <body id="page_courses">, but it doesn't.  However, the home page DOES work and says: <body id="page_home">, so I know I'm doing something right.  I just must have a setting wrong for the "courses" menu item/article.

Any suggestions?  Is that enough info to go on?

I'm a Joomla newbie, btw.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Avinash ZalaWeb Expert

try this:

$menu = &JSite::getMenu();
$active = $menu->getActive();
<body id="page_<?php echo $active->alias; ?>">

I think you are doing ok.

I figured out the problem.  I called the hosting company, and they said the code I was using wouldn't work because the name servers weren't pointed there yet, and I was using a pre propogation IP address.  They gave me a static IP address, and that fixed the problem!

Thank you!