07-24-2023, 10:26 AM
Use the $id variable in node.tpl.php to make themes allow things other than long vertical lists of content. For example, you could check whether $id is 1, and if so wrap the node in a div which puts it in a big highlight zone at the top right of the page. (This is useful when combined with the 'make sticky at top of lists' function.) Then you could have two columns some way lower down the page, containing $ids between 2 and 8 and 9 and 15.
Sometimes you might need to check something other than the $id number to determine which 'zone' to place a node into. In this case, it can be very helpful to do some of the checking in a hook_preprocess_node function (which you can place in your template.php file as themename_preprocess_node) which contains a static variable which you can use to store the result of checks on nodes which have already been shown on the page. For example, I use this to display a date heading above nodes providing a node of that date has not already been shown, like so:
if ($vars['teaser']) {
static $last_date;
$date = format_date($node->created, 'custom', 'l jS F');
if ( $date != $last_date ) {
$vars['show_date'] = TRUE;
$last_date = $date;
}
else {
$vars['show_date'] = FALSE;
}
}
Sometimes you might need to check something other than the $id number to determine which 'zone' to place a node into. In this case, it can be very helpful to do some of the checking in a hook_preprocess_node function (which you can place in your template.php file as themename_preprocess_node) which contains a static variable which you can use to store the result of checks on nodes which have already been shown on the page. For example, I use this to display a date heading above nodes providing a node of that date has not already been shown, like so:
if ($vars['teaser']) {
static $last_date;
$date = format_date($node->created, 'custom', 'l jS F');
if ( $date != $last_date ) {
$vars['show_date'] = TRUE;
$last_date = $date;
}
else {
$vars['show_date'] = FALSE;
}
}