Drupal 7 blog customized teaser

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.

jQuery edit in place – build your own!

I’m working on an application for mobloom.com enabling one of their customers (Discovery) to mobilize the TV shows and as part of this application, edit in place is required. Continue reading

Room for yet another PM tool?

It may sound like the stupidest thing to do, but I’m currently spending some of my spare time on building yet another project management tool, and yes, this is also based on rails… Continue reading

Sitewide Posts

Sitewide Posts plugin manifest

PHP performance

I’m currently upgrading blog.politiken.dk from version 1.1.1 to 2.7 and during the process I’m also trying to locate PHP blunders and bugs from the past Continue reading

Follow

Get every new post delivered to your Inbox.