Use CCK to make a unique front page

Last modified: February 26, 2008 - 04:56

The Lullabots suggested this one: If you want a custom front page, one way to do it is to use the Content Creation Kit. Basically, you make a custom content type which you will use only for your front page.

  • Make a new content type called "home."
  • Define a field for each area of your front page: "tip of the day", "about the site", whatever. Probably all text fields.
  • Create a "node-home.tpl.php" file. Remember, when Drupal is showing CCK nodes, it automatically looks for a node--NAMEOFTYPE.tpl.php file. So you don't need to change template.php.
  • Format each field that you defined. If you created a field called "tip of day", you would do this...
  • <div id="custom_html_div">
    <h2>Tip of the Day<h2>
    <?php print $node->field_tip_of_day[0]['view']; ?>
    </div>

    You can get a list of what your fields are named by going to the "manage fields" tab under administer->content->content types.

  • Then create one node of this type and make it your front page. Like if it's node 34 you go to Administer->General Settings>Default Front Page and set that to "node/34" You could theoretically make other nodes of this type but the idea is that you're only going to need one node.

Now when authorized users/authors come to the site, they should see an "edit" tab right on the front page, letting them change each section easily. And you have a separate .tpl.php file for your front page. Handy!

You can still mix in blocks. Print an existing region like this:

<?php print theme('blocks', 'left_sidebar'); ?>

Or a custom region:

<?php print theme('blocks', 'home_page_region'); ?>

 
 

Drupal is a registered trademark of Dries Buytaert.