I saw lot of questions and answers on this but I can't find solution. I need to show last posts trough tpl file and I can't figure how to do it. Also I don't know what to put in my tpl file.
Edit!: This is my hook_block_view () function and if I send data at the end of it like theme('item_list', ... it works perfectly. But I need to send it to my custom tpl file and when I do that it won't properly display list. I think that there is problem in .tpl file.
<?php
function last_5_user_posts_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'last_5_user_posts':
// Capture the image file path and form into HTML with attributes
$image_file = file_load(variable_get('last_5_user_post_image', ''));
$image_path = '';
if (isset($image_file->uri)) {
$image_path = $image_file->uri;
}
$image = theme_image(array(
'path' => ($image_path),
'alt' => t('Image description here.'),
'attributes' => array('class' => 'class_name'),
'width' => '12',
'height' => '12',
));
$block['subject'] = t('My last posts');
if (user_access('access content')) {
// Use our custom function to retrieve data.
$result = last_5_user_posts_contents();
// Array to contain items for the block to render.
$items = array();
// Iterate over the resultset and format as links.
foreach ($result as $node) {
$items[] = array(
'data' => $image.l($node->title, 'node/' . $node->nid),
);
}
// If there is no nodes
if (empty($items)) {
$block['content'] = t('No posts available.');
}
else {
// Pass data through theme function.
// $block['content'] = theme('last_5_user_posts_output', array(
// 'items' => $items));
$govno = 'Govno!';
$listitems = array('items' => $items);
$block['content'] = theme('last_5_user_posts_output', array(
'items' => $items));
}
}
return $block;
}
}
And my .tpl file for now contain just:
<div class="field-items"<?php print $content_attributes; ?>>
<ol style="list-style: circle">
<?php foreach ($items as $delta => $item): ?>
<li>
<div class="field-item" style="color: red;"><?php print render($item); ?></div>
</li>
<?php endforeach; ?>
</ol>
</div>
If I create array:
$test[1] = 'Test!';
$test[2] = 'Test2!';
$test[3] = 'Test3!';
And send it trough $block['content'] like this
$block['content'] = theme('last_5_user_posts_output', array(
'test' => $test));
It works pefectly! But for $items it won't work. How to optimize $items to get it in .tlp??