3

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.

jgonza73
  • 344
  • 1
  • 10
  • 1
    The page you click on the slider becomes a child of current (home) page since it's not in a menu. – Shaz May 28 '12 at 11:24

2 Answers2

2

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 .

Pramod Kumar Sharma
  • 7,851
  • 5
  • 28
  • 53
  • 1
    You shouldn't have to make a hidden menu item for each article, only for the parent category of the articles. Less hidden menu items to create that way. – Brent Friar May 28 '12 at 15:31
  • I do it on every site I build. There are always pages that you need nice URLs for that do not need to be in a menu. Just create a menu called Admin links or something like that. Don't assign it to any modules. Add anything you need an itemID or clean URL. – Brent Friar May 29 '12 at 20:28
  • It works! I have created a menu without any module linked. I choose the category of article I wanted to use, and that's all. Thanks! – jgonza73 May 30 '12 at 06:27
  • If its works then you can accept the answer to make it useful for all users..:) – Pramod Kumar Sharma May 30 '12 at 06:35
0

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.

Lumis
  • 21,517
  • 8
  • 63
  • 67