Hoe bepalen of de gebruiker de homepage bekijkt

From Joomla! Documentation

This page is a translated version of the page How to determine if the user is viewing the front page and the translation is 100% complete.
Other languages:
English • ‎Nederlands • ‎español • ‎français

Joomla 1.0 Joomla! 1.0

In Joomla! 1.0.x was het mogelijk te bepalen of de gebruiker de homepage bekijkt door code zoals deze te gebruiken:

<?php
if ($option == 'com_frontpage' || $option == '') {
	echo 'This is the front page';
}
?>

Joomla 1.5 Joomla! 1.5

Maar in Joomla! 1.5.x is de com_frontpage component niet langer aanwezig. Dit is hoe hetzelfde resultaat te bereiken in Joomla! 1.5.x

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

Dit werkt door te controleren of het huidig actieve menu-item het standaard menu-item is.

 Joomla 2.5 Joomla 3.x Joomla! 2.5 en 3.x serie

Er zijn enkele verschillen in 1.6/1.7/2.5 om Strict Standards fouten te voorkomen. Gebruik de volgende code voor een site waar alle inhoud in de zelfde taal is:

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

Voor meertalige websites hangt de homepage af van de momenteel gekozen taal, zodat u code zoals deze moet gebruiken:

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

Voor meertalige sites, kan het ook nodig zijn om specifieke code/html voor alle standaard homepages te tonen.

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