Skip to content

Commit

Permalink
BlogHelper::getRelatedPosts() にオプションを指定できるようにした。
Browse files Browse the repository at this point in the history
・recursive
・limit
・order
  • Loading branch information
ryuring committed Aug 20, 2012
1 parent 965ec15 commit 02baf96
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions baser/plugins/blog/views/helpers/blog.php
Expand Up @@ -744,12 +744,20 @@ function getParentCategory($post) {
* @return array
* @access public
*/
function getRelatedPosts($post) {
function getRelatedPosts($post, $options = array()) {

if(empty($post['BlogTag'])) {
return array();
}

$options = array_merge(array(
'recursive' => -1,
'limit' => 5,
'order' => 'BlogPost.posts_date DESC'
), $options);

extract($options);

$tagNames = array();
foreach($post['BlogTag'] as $tag) {
$tagNames[] = urldecode($tag['name']);
Expand Down Expand Up @@ -778,7 +786,9 @@ function getRelatedPosts($post) {
// 毎秒抽出条件が違うのでキャッシュしない
$relatedPosts = $BlogPost->find('all', array(
'conditions' => $conditions,
'recursive' => -1,
'recursive' => $recursive,
'order' => $order,
'limit' => $limit,
'cache' => false
));

Expand Down

0 comments on commit 02baf96

Please sign in to comment.