Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Created October 11, 2012 14:53
Show Gist options
  • Save jbroadway/3872942 to your computer and use it in GitHub Desktop.
Save jbroadway/3872942 to your computer and use it in GitHub Desktop.
Elefant CMS - Blog headlines with icons
{% if dates %}
{! admin/util/dates !}
{% end %}
<ul>
{% foreach posts %}
<li>
{% if dates %}{{ loop_value->ts|I18n::short_date }} {% end %}
<a href="/blog/post/{{ loop_value->id }}/{{ loop_value->title|URLify::filter }}">
<img src="{{ loop_value->img }}" />
{{ loop_value->title }}</a>
</li>
{% end %}
</ul>
<?php
/**
* Displays the latest blog posts with thumbnails extracted from the post body.
*/
$default_img = '/files/default_post_icon.png';
$width = 60;
$height = 36;
$limit = 10;
if (! $this->internal) {
$page->layout = $appconf['Blog']['layout'];
$page->title = i18n_get ('Latest Posts');
}
require_once ('apps/blog/lib/Filters.php');
require_once ('apps/filemanager/lib/Functions.php');
$posts = blog\Post::query (array ('id', 'ts', 'title', 'body'))
->where ('published', 'yes')
->order ('ts desc')
->fetch_orig ($limit);
foreach ($posts as $k => $post) {
if (preg_match ('/<img.*?src="(.*?)"/i', $post->body, $matches, 0, 1)) {
$posts[$k]->img = filemanager_get_thumbnail (ltrim ($matches[1], '/'), $width, $height);
} else {
$posts[$k]->img = $default_img;
}
}
$dates = (isset ($data['dates']) && $data['dates'] === 'yes') ? true : false;
echo $tpl->render ('blog/postswithicons', array (
'posts' => $posts,
'dates' => $dates
));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment