In the theme I’m working on I want to use the block “Recent blog posts” which is part of the blog module. But the “Recent blog posts” shows a list of minimum 2 blog posts as a list and I want to show 1 blog post in my teaser.
You can achieve this by using the hook_block_view_MODULE_DELTA_alter inside your template.php file where the MODULE is “blog” and DELTA is “recent”, so in my case where my theme is called “smackblue” the function name is “smackblue_block_view_blog_recent_alter”:
/**
* hook_block_view_MODULE_DELTA_alter()
*/
function smackblue_block_view_blog_recent_alter (&$data, $block) {
$content = $data['content'];
if ($content['blog_list']) {
$result = db_query('SELECT n.nid FROM {node} n WHERE n.type = :type ORDER BY created DESC LIMIT 1', array(':type' => 'blog'));
$obj = $result->fetchObject();
$node = node_load($obj->nid);
$data['content'] = node_view($node, 'full');
}
}
I’m not keen on using db_query inside my template.php file, but I did not find any other way to get the recent blog post, if you know how, let me know. Now the teaser blog is being themed the same way as every other blog post in my theme.