From 7d914fc898f3e826f2e1045ad8eba6903a4a4473 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Mon, 13 Jan 2014 10:42:27 +0700 Subject: [PATCH] Add related posts Add related posts feature base on post tag. --- system/config.ini | 1 + system/includes/functions.php | 64 +++++++++++++++++++++++++++++++++---------- themes/clean/css/style.css | 17 ++++++++++++ themes/clean/post.html.php | 1 + themes/default/css/style.css | 51 +++++++++++++++++++++++++++++++++- themes/default/post.html.php | 1 + 6 files changed, 119 insertions(+), 16 deletions(-) diff --git a/system/config.ini b/system/config.ini index c878606..82e0e68 100644 --- a/system/config.ini +++ b/system/config.ini @@ -30,6 +30,7 @@ tag.perpage = "10" archive.perpage = "10" search.perpage = "10" profile.perpage = "30" +related.count = "4" rss.count = "30" json.count = "10" diff --git a/system/includes/functions.php b/system/includes/functions.php index 1706d70..f3b7749 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -613,6 +613,39 @@ function get_keyword($keyword){ return $tmp; } +// Get related posts +function get_related($tag) { + + $perpage = config('related.count'); + $posts = get_tag($tag); + $tmp = array(); + $req = $_SERVER['REQUEST_URI']; + + foreach ($posts as $post) { + $url = $post->url; + if( strpos($url, $req) === false){ + $tmp[] = $post; + } + } + + $total = count($tmp); + + if($total >= 1) { + + shuffle($tmp); + + $i = 1; + echo ''; + } + +} + + // Helper function to determine whether // to show the previous buttons function has_prev($prev){ @@ -846,25 +879,11 @@ function menu(){ } } -// Menu -function search() { - echo << - - - -EOF; - if(isset($_GET['search'])) { - $url = site_url() . 'search/' . $_GET['search']; - header ("Location: $url"); - } -} - // Auto generate menu from static page function get_menu() { $posts = get_spage_names(); - ksort($posts); + krsort($posts); echo '