latest post plugin

This commit is contained in:
dignajar 2016-01-08 12:46:52 -03:00
parent cc069d988d
commit 5441a22ccf
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,15 @@
{
"plugin-data":
{
"name": "Latest posts",
"description": "Shows the latest posts published.",
"author": "Bludit",
"email": "",
"website": "https://github.com/dignajar/bludit-plugins",
"version": "1.0",
"releaseDate": "2016-01-08"
},
"home": "Home",
"show-home-link": "Show home link"
}

View File

@ -0,0 +1,59 @@
<?php
class pluginLatestPosts extends Plugin {
public function init()
{
$this->dbFields = array(
'label'=>'Latest posts',
'amount'=>5
);
}
public function form()
{
global $Language;
$html = '<div>';
$html .= '<label>'.$Language->get('Plugin label').'</label>';
$html .= '<input name="label" id="jslabel" type="text" value="'.$this->getDbField('label').'">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Amount of posts').'</label>';
$html .= '<input name="amount" id="jsamount" type="text" value="'.$this->getDbField('amount').'">';
$html .= '</div>';
return $html;
}
public function siteSidebar()
{
// This function is declared in 70.posts.php
$posts = buildPostsForPage(0, $this->getDbField('amount'), true, false);
$html = '<div class="plugin plugin-latest-posts">';
// Print the label if not empty.
$label = $this->getDbField('label');
if( !empty($label) ) {
$html .= '<h2 class="plugin-title">'.$label.'</h2>';
}
$html .= '<div class="plugin-content">';
$html .= '<ul>';
foreach($posts as $Post)
{
$html .= '<li>';
$html .= '<a href="'.$Post->permalink().'">'.$Post->title().'</a>';
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}