- On your Joomla 2.5 control panel, add New Article with a 404 title under Uncategorised category.
- Add New Menu Item with a 404 Error Page title then link your new article but make the Status Unpublished.
Click Save & Close. - Edit the newly created menu item 404 Error Page. Copy the Link content (e.g. index.php?option=com_content&view=article&id=121).
- Go to your joomla folder and copy error.php from templates/system/ folder to your default template folder (e.g. templates/itropicstemplate/).
- Open the newly copied error.php and add this line after the defined('_JEXEC') or die; line.
if (($this->error->getCode()) == '404') {
So, your error.php file should look like this.
header('Location: index.php?option=com_content&view=article&id=121');
exit;
}
- Replace index.php?option=com_content&view=article&id=121 with your link content as per step # 3.
- Visit your website and navigate to a non-existing page to test your custom 404 error page.
Alternative Way
- On your default template folder (e.g. templates/itropicstemplate), duplicate your index.php and rename it to error.php
- Open your error.php file and add the title line on your head part.
<head>
....
<title><?php echo $this->error->getCode(); ?> - <?php echo $this->title; ?></title>
....
</head> - Add the jimport line after the line <body>. So it will look similar to this:
<body>
<?php jimport( 'joomla.application.module.helper' ); ?>
...
...
</body> - On your main content where you normally place the syntax <jdoc:include type="component" />, replace that with your 404 error message like the one below.
<div style="width:100%;">
<h2>Oops...</h2>
<p>Sorry, we could not find the page you were looking for...</p>
<p> </p>
<p><a href="http://www.itropics.net">Go back to home page</a></p>
</div> - Now your menu and other modules will not show up on your 404 Error page. In this case, we need to use the JModuleHelper::getModulesyntax.
Let say, I want to show the menu module.
Change:<jdoc:include type="modules" name="menu" />
To:
<?php $module = JModuleHelper::getModule( 'menu' , 'Main Menu' );
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $module, $attribs); ?>getModule syntax is getModule( $name, $title ). More info about getModule can be found on http://docs.joomla.org/JModuleHelper/getModule.
If you want to display a Custom HTML module, $name is custom and $title is your title, so mine would be Footer - Column 1, like:<?php
$module = JModuleHelper::getModule( 'custom' , 'Footer - Column 1' );
echo JModuleHelper::renderModule( $module);
?>
If you want to display the DisplayNews module, $name is dn.
If you want to display the Search module, $name is search.