Drupal Snippets
Display something between node teasers in a view
Submitted by chris on August 16, 2006 - 01:18. Drupal SnippetsWork 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
Submitted by chris on June 25, 2007 - 00:59. Drupal SnippetsProblem:
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
Submitted by chris on June 12, 2006 - 02:45. Drupal Snippets<?php
$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;
Block Visibilty: Hide block in forums and admin section
Submitted by chris on September 16, 2006 - 21:42. Drupal SnippetsIn 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:
<?php
$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;
?>
Drupal: Print only on main page (or print on all but the main page)
Submitted by chris on October 10, 2006 - 18:08. Drupal SnippetsPrint 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?):

