Skip to content

Instantly share code, notes, and snippets.

@myles
Created April 5, 2011 14:16
Show Gist options
  • Save myles/903671 to your computer and use it in GitHub Desktop.
Save myles/903671 to your computer and use it in GitHub Desktop.
/**
* Implementation of hook_block().
*
* Displays the most recent 10 blog titles.
*/
function blog_block($op = 'list', $delta = 0) { global $user; if ($op == 'list') {
$block[0]['info'] = t('Recent blog posts');
return $block;
} else if ($op == 'view') {
if (user_access('access content')) {
$today = time();
$six_months_ago = strtotime("-6 months", $today);
$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 AND n.created >= $six_month
s_ago ORDER BY n.created DESC"), 0, 5);
if (db_num_rows($result)) {
$block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', arr
ay('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = t('Recent blog posts');
return $block;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment