forked from cynial/STBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecent_posts.php
More file actions
66 lines (51 loc) · 1.52 KB
/
Recent_posts.php
File metadata and controls
66 lines (51 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Plugin Name: 最新日志Widget
* Plugin URI: http://www.cnsaturn.com/
* Description: 显示博客最新日志
* Version: 0.1
* Author: Saturn
* Author Email: [email protected]
*/
class Recent_posts
{
private $_CI;
public function __construct(&$plugin)
{
$plugin->register('Widget::Posts::Recent', $this, 'show_recent_posts');
$this->_CI = &get_instance();
}
public function show_recent_posts($format)
{
/** 输出格式为空?*/
if(empty($format)) return;
/** 输出多少条? */
$list_size = setting_item('posts_list_size');
$list_size = ($list_size && is_numeric($list_size)) ? intval($list_size) : 10;
$posts = $this->_CI->stcache->get('Widget::Posts::Recent');
if(FALSE == $posts)
{
$posts = $posts = $this->_CI->db->select('slug, title')
->from('posts')
->where('type', 'post')
->where('status', 'publish')
->order_by('created', 'DESC')
->limit($list_size)
->offset(0)
->get()
->result();
$this->_CI->stcache->set('Widget::Posts::Recent', $posts);
}
if($posts)
{
foreach($posts as $post)
{
$wildcards = array('{permalink}', '{title}');
$replaces = array(site_url('posts/'. $post->slug), $post->title);
echo str_replace($wildcards, $replaces, $format) . "\r\n";
}
}
}
}
/* End of file Recent_posts.php */
/* Location: ./application/st_plugins/Recent_posts.php */