Joomla Frontpage vs Homepage

posted in: Joomla, PHP | 0

Just some notes about determining whether the user is viewing the “Homepage” of a Joomla site.

On my website I found that I needed to write some code so that my template could switch its layout depending on whether the user was viewing the “Homepage” or not.

Joomla doesn’t have the concept of a Homepage, but instead has a “Front page” however these two are not the same.

I use the Frontpage blog to show a table of articles. When the user clicks on a “read more” link, the full article is shown.
This works fine, except I don’t want the slider at the top of the page to be shown when the user is viewing an article as it takes up too much space and is distracting.

So I looked around for some code that I could use to determine if the user was viewing the “Home page”

The main Joomla website has code to determine whether the user is on the “Front page”. The code looks like this

getActive() == $menu->getDefault()) {
echo ‘This is the front page’;


However in the case of my site, Joomla considers the articles linked to by the Frontpage blog to also be on the front page, so this code was no use.

I found an alternative bit of code


which seemed to work on my local test site, but would not work on my Internet site 🙁
I’m not entirely sure how it could work at all because JRequest::getInt(‘Itemid’) returns a number i.e. an Int of the Itemid, but $menu->getDefault() returns a class.

I then found this solution which did work for me, but has some drawbacks.

The main drawback is that http://yoursite/ is treated as the homepage, but http://yoursite/index.php is not 🙁

In the end I decided not to use the code above, because of its drawback, and instead I’ve written this code, based on various snippets I found on the web.

0 ) {
$Id = substr($Id,0,strpos($Id,’:’));

if ($Id == $menu->getDefault()->query[‘id’])

The first part of the code gets the current Id (of the article), and the second part of the code checks if the “id” is that of the article attached to the menu’s default item.

Note. Although this solution works well for me, it may not work if you have multiple menus, in which case you may have to fall back to using

if (JURI::current() == JURI::base())