Drupal Snippets

Display something between node teasers in a view

Work in progess....

Drupal snippet to display something every X node in a view:

1) In the file views.module:

function theme_views_view_nodes($view, $nodes, $teasers = false, $links = true) {
$num_nodes = 0;
$display_at = X;
foreach ($nodes as $n) {
$node = node_load($n->nid);
$output .= node_view($node, $teasers, false, $links);
if (++$num_nodes == $display_at) {
$output .= "test";
$num_nodes = 0;
return $output;

Restrict Search To Certain Content Types Only


On a Drupal site, I want to restrict the search to a certain content type only. To avoid creating confusion for the user, I also want this to happening in the background (ie hidden). I also to not want to the advanced search turn on since it would expose everything to the user...

Drupal: Display a block of random members with picture and basic info

$fields = array();
$result2 = db_query('SELECT name, title, type, visibility, weight FROM {profile_fields} WHERE name IN ("profile_full_name", "profile_country") ORDER BY weight');
while ($record = db_fetch_object($result2)) { $fields[] = $record; }
$count = 2;

Drupal: Print only on main page (or print on all but the main page)

Print breadcrum on all page except home/front page...
<?php if (!$_REQUEST["q"]=="" && !(variable_get('site_frontpage', 'node')==$_REQUEST["q"]))
print $breadcrumb; ?>

In other words to only print something on the main page use:
if ($_REQUEST["q"]=="" || (variable_get('site_frontpage', 'node')==$_REQUEST["q"])) {
print ....;

It appears the following are not reliable or consistant (any longer?):

Block Visibilty: Hide block in forums and admin section

In the block under "Show block on specific pages:":
Select --> Show if the following PHP code returns TRUE (PHP-mode, experts only).
Enter the PHP code:

$match = TRUE;
if (arg(0) == 'forum') { $match = FALSE;}
if (arg(0) == 'node' && ctype_digit(arg(1))) {
$node = node_load(arg(1));
if ($node->type == 'forum') { $match = FALSE; }
if (substr($_SERVER["REQUEST_URI"], 0, 6) == '/admin') { $match = FALSE;}
return $match;