18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Theming a <strong>Module</strong><br />

* First draft!<br />

*<br />

* @pararm $delta<br />

* The name of the requested block.<br />

*/<br />

function single_blog_block_view($delta = '') {<br />

// Create an empty block.<br />

$block = array(<br />

'subject' => '',<br />

'content' => '',<br />

);<br />

// Check which block is being requested.<br />

if ($delta == 'recent') {<br />

// Set the block title.<br />

$block['subject'] = t('Recent blog posts');<br />

// Check if the user can access content.<br />

if (user_access('access content')) {<br />

// Retrieve the most recent nodes.<br />

$result = single_blog_list(SINGLE_BLOG_LIST_COUNT);<br />

// Create links for each blog entry.<br />

$items = array();<br />

foreach ($result as $node) {<br />

$items[] = array(<br />

'data' => l($node->title, 'node/' . $node->nid),<br />

'class' => array('node-' . $node->nid),<br />

);<br />

}<br />

}<br />

}<br />

if (!empty($items)) {<br />

// Theme the list of blog entries.<br />

$block['content'] = theme('item_list', array(<br />

'items' => $items));<br />

}<br />

return $block;<br />

}<br />

[ 96 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!