theme node pages
Hide the Node Title on a Page (6.x)
Hide Node Title by Content Type
You can hide node titles by specific content type by adding some code to your template.php file.
This example ignores the title on any node that is of the type "page" or "story". Note that it also saves the title to another variable for use in other parts of the page.tpl.php if desired. Also note that these instructions cover the case where the function in question doesn't exist. If you get an error that says "cannot redeclare function ...", then you need to add the code to the existing function. Finally, you may have to go to admin/build/themes and save the themes form there to rebuild the theme registry before the changes take affect.
<?php
function THEMENAME_preprocess_page(&$vars) {
// Titles are ignored by content type when they are not desired in the design.
$vars['original_title'] = $vars['title'];
if (!empty($vars['node']) && in_array($vars['node']->type, array('page', 'story'))) {
$vars['title'] = '';
}
}
?>Hide the Node Title on a Page (5.x)
Hide Node Title by Content Type
You can hide node titles by specific content type by adding some code to your template.php file.
This example ignores the title on any node that is of the type "page" or "story". Note that it also saves the title to another variable for use in breadcrumbs if desired.
<?php
// Titles are ignored by content type when they are not desired in the design.
$vars['breadcrumb_title'] = $vars['title'];
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (in_array($node->type, array('page', 'story'))) {
$vars['title'] = '';
}
}
?>This is where the code belongs in the _phptemplate_variables() function:
<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
// Titles are ignored by content type when they are not desired in the design.
$vars['breadcrumb_title'] = $vars['title'];
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (in_array($node->type, array('page', 'story'))) {
$vars['title'] = '';
}
}
break;
}
return $vars;
}
?>Hide Node Title on Front Page
Get nodes as an array for greater flexibility
By default, in your page.tpl.php you have $content which contains all the nodes and other things like pagination..etc. The snippet below tries to give more flexibility by breaking down $content, and breaking down nodes themselves into an array of nodes. Precisely, what happens is:
- In page.tpl.php: You get a new array (YES!) called
$nodes, contains the XHTML for each node. - In page.tpl.php:
$contentnow does NOT contain the nodes. It contains some other things like pagination..etc
Be aware that this snippet doesn't really give you any difference if you didn't adjust your page.tpl.php to exploit the extra flexibility of having nodes as an array. Some examples of doing neat things with $nodes array can be found after the snippet below.
Here comes the PHP snippet, place this in your template.php:
<?php
function yourtheme_node($node, $teaser = 0, $page = 0) {
set_themed_node(phptemplate_node($node, $teaser, $page));
}
function set_themed_node($node = NULL) {
static $themed_nodes;
if ($node) {
$themed_nodes[] = $node;
}
else {
return $themed_nodes;
}
}
function _phptemplate_variables($hook, $vars) {
$myvars = array();
switch ($hook) {
case 'page':
$myvars['nodes'] = set_themed_node();
break;
}
Print the content-type name or label with the 'submitted' info
To print the name of a node's content type, add these lines into your theme's node.tpl.php file.
Print the names for all types of nodes
<?php
print node_get_types('name', $node);
?>Exclude a single content type's name from being printed
<?php
print $node->type != 'page' ? node_get_types('name', $node) : '';
?>Exclude multiple content types' names from being printed
<?php
if (!in_array($node->type, array('story', 'page'))) {
print node_get_types('name', $node);
}
?>See http://api.drupal.org/api/function/node_get_types/ for more information.
