Question

I've seen in Joomla documentation the way to detect if you are in Frontpage while creating a template in Joomla 2.5. This is the code:

<?php 
$app = JFactory::getApplication(); 
$menu = $app->getMenu(); 
if ($menu->getActive() == $menu->getDefault()) { 
    echo 'This is the front page'; 
} 
?>

This works when you are at home page (or clicking on Home menu), but I have an slider in home page, and I link in the slider to an article which is not in any menu item in the application. When I load this article the code above returns as I were at frontpage. I guess that if I doesn't click on any menu item, $menu->getActive() doesn't change.

Any suggestion? Thanks in advance.

Was it helpful?

Solution

You can do one thing to solve this problem. Create a hidden menu of all the article links which are linked in the sliders.By creating hidden menu the link will be initialized and $menu->getActive() will work for all the links..Hopefully it will works for you .

OTHER TIPS

I wish to add to the present answer and provide some clarifications.

In order for the menu selection to be detected the page requires to be assigned to a menu item. If this is a hidden menu than the link to such a page called My Page would be:

/index.php/my-page - “my-page” is the menu title alias for this item

However, if one wants to show the correct hierarchy in the breadcrumbs for the same page, then the menu hierarchy would have to be replicated in the hidden menu.

For example if My Page is under My Articles main menu item, then in the hidden menu you should add “My Articles” item, of the type: Menu Item Alias, which is in the Systems submenu of the menu type field. The My Page item should be a sub-menu item of My Articles.

The “My Articles” menu item in the hidden menu must have a different menu alias than the same one in the main menu hence the new link to My Page would look like:

/index.php/my-articles2/my-page

To create a hidden menu, one simply creates another menu. It does not matter whether one creates a module for it or not, but if one does then one just should not assign any position to that module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top