The following pages outline a variety of ways you can create a custom home page for your Drupal site.
Also, check out these helpful video lessons that illustrate one or more of the techniques:
[[[[Add description]]]]
This lesson has been designed for Drupal 5.x, since at the time of writing not all necessary modules were yet available for Drupal 6. When possible, this lesson will be upgraded with any additional details needed for Drupal 6 compatibility.
This lesson will use a sample CCK Content Type called "Article". You can create or import this Content Type to follow along (grab the import code from below ***ADD CODE***), or else simply apply the concepts to your own content types. Before beginning on your own home page, it is important that you fully develop the Content Types you will be using for your site (or at the least, those that will be involved with the home page in any way). Since your Content Types make up the bulk of what your home page will actually consist of, it's important to have them all sorted out before dealing with your home page. If you'd like some guidance on setting up your own Content Types and fields before proceeding with this lesson, please visit the following resources:
-
-
(your Content Types may have considerably more fields, or additional types such as Image fields)
You might wonder why you need the teaser_title and teaser_text fields, instead of just using Drupal's own node title and automatically generated teaser text. On a more complex home page, it becomes important to ensure that certain blocks of content will always consistently fit into the specific amount of space that's been allotted to them (enforced during entry of the content with the field's "maximum length" setting). On more professional sites, a short "synopsis" of each item of content is generally preferable to an auto-generated chunk of text cropped off of the beginning of the full content's page, which is Drupal's default behavior. Having a separate teaser_title is more optional, but if you choose to have one, will allow you to set a different or shorter version of the title to more easily fit into the confines of the home page, while still allowing you to have a full length title for the actual page. Setting up dedicated text fields in CCK for the teaser and title helps to accomplish all of these purposes.
If you prefer to go "all out" with your Article content type, here are some additional field options to choose from (including these just for your reference/ideas - they are not used in the lesson):
When your Article content type is fully completed, your editor/staff will just need to click Create Content -> Article, and be presented with exactly all of the fields they need to fill out and images to upload to completely and correctly produce an article (with no coding - other than maybe light HTML for the article formatting itself unless you give them a WYSIWYG editor).
I'm assuming you want to be able to select various articles/pages from the site to feature in the middle row of the home page, in a specific order (the top one being the Cover Story). The way to do that is to create a View that has its order controlled by a Node Queue. To make your Node Queue, go to admin/content/nodequeue/add/nodequeue . Enter a title (e.g. home_articles_queue), Queue size of 4, and for Type choose Article (assuming you've made the CCK type). You might also like to check "Reverse in admin view", as this will cause queue items to drop from the bottom of the list rather than the top as new items are added, which may or may not make better sense to you (if you do this, you'll also probably want to adjust the NodeQueue: Queue Position sort criteria option to "Descending" in the View you'll make in the step below). Node Queue also adds a new tab to pages of the content type you selected in the previous step (Article), and you can click that tab from any page and add the page into the queue. You can then reorder the queue as you like by going to admin/content/nodequeue and clicking on the View option of the queue you want to adjust (and you can also use the search field to add additional content directly to the Node Queue).
Next comes the View that is ordered according to the Node Queue. You can make your own View and add the Node Queue "Filter" and "Sorting" options, or you can use the default nodequeue View that is generated for each nodequeue as a starting template to customize. Go to admin/build/views and look down in the "Default Views" area for a View called "nodequeue_1". Click the Add link to the far right and you'll call up a Views page containing the default options for that View. Change the name some something else (e.g. home_articles), uncheck Provide Page View. Scroll down to the Block options - ensure List View is selected, remove the title, set the # to 4, and uncheck More link. Next add the needed fields from your Article content type (e.g. at least the teaser-image, or other fields if you decide to make those as text/images/css). For Filters, add Node: Published (set to yes), and Node: Type (set to Article). When you're finished, save the View.
To add a View to Panels you first need to specifically tell Panels which Views you want to make available for it to use. To do this, go to: admin/panels/views, choose the name of the View you just created above from the selection menu, and press Create panel view. Copy and paste the View's name into the Panel view title field - you can leave all the other settings as default - scroll down and submit the page.
You can create a node of any type (e.g. Page, Story, or a custom type), add the content to it that you'd like to include on your home page, and then set it as the home page with the setting at: admin/settings/site-information
The page.tpl.php file is where you place "highest level" HTML structure of your site (e.g. the <html>, <body>, etc tags). You can create a separate "overridden" version of your page.tpl.php file to design a slightly modified or even completely different template for your home page - this is done by making a file in your theme's directory called page-front.tpl.php (read more about page-front.tpl.php).
<body> tag.
You can design/code your whole home page's content within the same main template file that the rest of your site's pages use (page.tpl.php), by wrapping the following bit of PHP code around all the code/content that is meant to be shown only for the home page:
If Drupal sees that the front page is currently being viewed ($is_front = true), it will display the contained code - otherwise it will completely skip it as if it didn't exist:
<?php if ($is_front) : ?>
... everything that's for the front page including hard coded HTML and text and/or addition Drupal regions you could define in template.php (such as a new region called "home" and assign any Views blocks you make for use on the home page to this region at admin/build/block) ...
<?php endif; ?>You can even embed one or more Views directly in the template file here if you'd like.
Learn more about making new custom regions (regions in Drupal 5 and regions in Drupal 6), and placing blocks into those regions.
Reference: HowTo build your home page with regions/blocks
One interesting method of making a home page that offers a mix of easy editing of static fields, plus the ability to embed blocks and other dynamic content, is by making your front page using CCK. This might be a good choice if what you're after is an easily editable set of pre-defined fields (which would, for instance, make it easy for your non-tech-savvy client to edit basic static information without coding anything) with additional dynamic content drawn in through embedded Regions/blocks or Views.
Home, and Type to home.Body from the Body field label setting. If the label is empty, the Body field will not be included.Promoted to front page and set the Attachments option to Disabled.Disabled.
Home. Scroll to the bottom of the page and click "Submit configuration".<h1 class="title"><?php print $title; ?></h1> (or something similar, containing $title).<?php if (!$is_front) : ?>
<h1 class="title"><?php print $title; ?></h1>
<?php endif; ?>You can set up permissions so that only the admin (user 1) ever sees "Home" as an available content type on the Create Content page. Of course you only want "one" Home page, so it doesn't make sense to be shown the option to make more Home pages.
[note: will migrate the below section about embedding Blocks, Regions, and Views into template files to a separate dedicated article, and reference it from this page]
There are a variety of ways to easily embed dynamic content into your node-home.tpl.php file.
The following uses the default Search block as an example, to illustrate the technique for embedding any Block:
<?php
$block = module_invoke('search', 'block', 'view', 0);
print $block['subject'];
print $block['content'];
?>There are just 2 parts to the above code that you need to customize in order to display any particular block, which are highlighted in the sample below:
$block = module_invoke('search', 'block', 'view', 0);
You can embed any default or custom Region (populated with as many Blocks as you wish, which you can control and arrange at Administer > Site building > Blocks).
When you add custom Regions to your theme you have to include the default regions as well or they will no longer be used (you can, however leave out any that you don't want to keep). Add as many custom Regions as you wish. The following is for Drupal 6.
First add the Region(s) to your ThemeName.info file:
regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[home_custom] = Custom home region nameThen you can use the following code in node-home.tpl.php:
<?php print theme('blocks', 'home_custom'); ?>You can embed a View if it has a Block display using the Region method above. However it's also very easy to embed a View directly into the node-home.tpl.php file. (I need to check if this is true, but I believe a benefit of directly embedding a View instead of defining extra Regions is that it has better performance for your site). Here is info on embedding Views with Drupal 5. The following illustrates how to embed a View using Views 2 with Drupal 6 (more advanced options are also available):
<?php
$view = views_get_view('viewname');
print $view->preview('default');
?>Where viewname is the name of your View, and default can be changed to the page_# or block_# of any Display in your View. For instance, to embed the first Block Display defined in the View, you could use block_1.
The following is an example extracted from the node-home.tpl.php of absolutecross.com, which is currently being redeveloped in Drupal. It is made up of 3 custom text fields, and will soon add 2 embedded Views as well:
<div id="home_left">
<?php print $node->field_home_welcome[0]['view'] ?>
<?php print $node->field_home_featured_content[0]['view'] ?>
</div>
<div id="home_right">
<?php print $node->field_home_featured_sites[0]['view'] ?>
</div>