Change the Default Homepage

It's easy to change the default home page for Pixaria from the default gallery view and create a custom home page. In this tutorial, we will create a custom home page from scratch but it's worth noting that you can edit the default homepage files as well if you wish.

Quick Customisation Option

If you don't want to create your own home page from scratch, a quick solution is to customise the default home page files.

The default home page PHP script index.welcome.php is located in the base directory of your Pixaria installation and its corresponding template file is resources/templates_default/index.tpl. If you decide to use this method, skip directly to step 4 to make sure you provide users with a link to the gallery page.

Step 1 - Create a PHP script for your page

If you're not already using a custom theme with your Pixaria installation, you can create a customised theme by making a duplicate of the 'Illuminux' theme that comes with Pixaria and renaming the directory to a theme name of your choice (the name must not include spaces).

The first thing to do once you are working on a custom theme is to create a new text file in a text editor of your choice such as TextMate, BBEdit or DreamWeaver and paste in this code:

<?php

// Set up constant for front end activities
define("WORKSPACE","FE");

// Set the include path for files used in this script
ini_set("include_path","resources/includes/");

// Load in the Pixaria settings and includes
include ("pixaria.Initialise.php");

// Send HTTP header and don't cache
pix_http_headers("html","");

// Go to login page if the default action for logged out users 
// is to require logging in or registering before viewing content
pix_login_redirect();

// Initialise the smarty object
$smarty = new Smarty_Pixaria;

// Set the page title for the home page
$smarty->assign("page_title","My Home Page");

// Load the template for the home page
$smarty->display('homepage/index.html');
?>

If you want to set a title to display in the top of your web browser window, you can enter one between the quote marks in the page_title assign method.

At the bottom of the code sample, you will see a reference to the template we are going to use for this page which is loaded by a method of the Smarty class called display(). You should change the parameter for this method to the name of the template you want to display which in this case will be index.html.

Now save this file with a .php extension in the document root of your Pixaria installation. In this example, we will assume that the new page is called custom.homepage.php but you can call the file anything you wish.

Step 2 - Create the template for your new page

You now need to create a new template file with the same name that you entered into the display() function in the index.php file. To do this, create a new text file in your text editor and save it into the templates directory in the new theme folder you created in step one. In this example, the text file will be saved in a folder called homepage with the name index.html.

With the text file still open, paste the following code into the file and then save the changes:

<!-- INCLUDE THE TOP HTML TEMPLATE -->
{include_template file="index.layout/main.header.tpl"}

(this is where you put the contents of your page as HTML)

<!-- INCLUDE THE BOTTOM HTML TEMPLATE -->
{include_template file="index.layout/main.footer.tpl"}

At this point you can test whether your new page works correctly by going to the direct URL of the new PHP script you've created which will be something like this:

http://www.mysite.com/custom.homepage.php

You should see the default Pixaria layout with navigation and page footer and the text '(this is where you put the contents of your page as HTML)' in the middle of the page.

Step 3 - Set the new page as the default homepage

To make your new, custom home page the default view when users click onto the 'Home' link in the Pixaria navigation toolbar, you now need to edit the file index.php in the base directory of your Pixaria installation.

Open the file index.php in a text editor and locate the following code:

case 'index.php': case '':	
	require_once("index.welcome.php");
	exit;	
break;

Now change the text require_once("index.welcome.php"); so the code reads as follows:

case 'index.php': case '':	
	require_once("custom.homepage.php");
	exit;	
break;

This change replaces the default home page index.welcome.php with your new custom home page and ensures that anyone browsing to your site will see your custom home page as the default view when clicking on the 'home' navigation item. Save the file and test that the change is working by browsing to your site's home page.

Step 4 - Add a link to the gallery page to your navigation

The final step is to create a new link in the main site navigation to help users find their way to the gallery listing. To do this, you will need to edit the template file index.layout/main.header.tpl and locate the line which described the home page link:

<li><a href="{$base_url}{$fil_index}" class="navigation-link">##NAVIGATION_03##</a></li>

Now add a new link to the gallery view page directly under the homepage link like this:

<li><a href="{$base_url}{$fil_index}" class="navigation-link">##NAVIGATION_03##</a></li>
<li><a href="{$base_url}{$fil_index_gallery}" class="navigation-link">Galleries</a></li>

Save the updated file to your site and you will now have a new navigation menu item for the gallery page next to the 'Home' link.

Tips and troubleshooting

If you've made a custom theme for the first time, you will need to upload the entire theme directory to Pixaria and then choose it as your selected theme from the appearance control panel.

If you're using Smarty's template caching to improve the performance of your site, be sure to flush the template cache to see your changes.


Last edited on Thursday April 29 2010 at 18:18:53