Skip to content

Instantly share code, notes, and snippets.

@rocketeerbkw
Created February 6, 2012 07:26
Show Gist options
  • Save rocketeerbkw/1750424 to your computer and use it in GitHub Desktop.
Save rocketeerbkw/1750424 to your computer and use it in GitHub Desktop.
Custom module for showing blocks in Drupal 6
name = Custom Module
description = Custom module
core = 6.x
dependencies[] = blog
<?php
/**
* Implementation of hook_block().
*
* Supplies some custom blocks:
* Recent blog posts
* Recent booklet posts
* Static block of text
*/
function timmyt_custom_block($op = 'list', $delta = 0) {
global $user;
// Change how many blog titles you want to show here
$number_blogs = 5;
$number_booklets = 5;
// This section tells drupal the name of your block that shows up on Site Building > Blocks
if ($op == 'list') {
$block[0]['info'] = t('Custom Module: Recent blog posts');
$block[1]['info'] = t('Custom Module: Recent booklet posts'); // Copy this line for every new block you have.
$block[2]['info'] = t('Name of another custom block'); //Notice how the number in $block[2] needs to be incremented for each one you have
return $block;
}
// This section tells drupal the block title AND block content for your block
else if ($op == 'view') {
switch ($delta) {
case 0: // Notice how the number here matches the number in $block[0] in the first section
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, $number_blogs);
if ($node_title_list = node_title_list($result)) {
$block['content'] = $node_title_list;
$block['content'] .= theme('more_link', url('blog'), t('Read the latest blog entries.'));
$block['subject'] = t('Recent blog posts');
return $block;
}
}
case 1: // Notice how the number here matches the number in $block[1] in the first section
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'booklet' AND n.status = 1 ORDER BY n.created DESC"), 0, $number_booklets);
if ($node_title_list = node_title_list($result)) {
$block['content'] = $node_title_list;
$block['content'] .= theme('more_link', url('blog'), t('Read the latest blog entries.'));
$block['subject'] = t('Recent booklet posts');
return $block;
}
}
case 2: // Notice how the number here matches the number in $block[2] in the first section
// You only need to lines if you want to show a static block of text
$block['content'] = 'This is my blocks static content!';
$block['subject'] = t('Title of another block');
return $block;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment