Browse Source

Add related posts

Add related posts feature base on post tag.
pull/9/head
Danang Probo Sayekti 12 years ago
parent
commit
7d914fc898
6 changed files with 119 additions and 16 deletions
  1. +1
    -0
      system/config.ini
  2. +49
    -15
      system/includes/functions.php
  3. +17
    -0
      themes/clean/css/style.css
  4. +1
    -0
      themes/clean/post.html.php
  5. +50
    -1
      themes/default/css/style.css
  6. +1
    -0
      themes/default/post.html.php

+ 1
- 0
system/config.ini View File

@ -30,6 +30,7 @@ tag.perpage = "10"
archive.perpage = "10" archive.perpage = "10"
search.perpage = "10" search.perpage = "10"
profile.perpage = "30" profile.perpage = "30"
related.count = "4"
rss.count = "30" rss.count = "30"
json.count = "10" json.count = "10"


+ 49
- 15
system/includes/functions.php View File

@ -613,6 +613,39 @@ function get_keyword($keyword){
return $tmp; 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 '<div class="related"><h4>Related posts</h4><ul>';
foreach ($tmp as $post) {
echo '<li><a href="' . $post->url . '">' . $post->title . '</a></li>';
if ($i++ >= $perpage) break;
}
echo '</ul></div>';
}
}
// Helper function to determine whether // Helper function to determine whether
// to show the previous buttons // to show the previous buttons
function has_prev($prev){ function has_prev($prev){
@ -846,25 +879,11 @@ function menu(){
} }
} }
// Menu
function search() {
echo <<<EOF
<form id="search-form" method="get">
<input type="text" class="search-input" name="search" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}">
<input type="submit" value="Search" class="search-button">
</form>
EOF;
if(isset($_GET['search'])) {
$url = site_url() . 'search/' . $_GET['search'];
header ("Location: $url");
}
}
// Auto generate menu from static page // Auto generate menu from static page
function get_menu() { function get_menu() {
$posts = get_spage_names(); $posts = get_spage_names();
ksort($posts);
krsort($posts);
echo '<ul>'; echo '<ul>';
echo '<li><a href="' . site_url() . '">Home</a></li>'; echo '<li><a href="' . site_url() . '">Home</a></li>';
@ -883,6 +902,21 @@ function get_menu() {
} }
// Search form
function search() {
echo <<<EOF
<form id="search-form" method="get">
<input type="text" class="search-input" name="search" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}">
<input type="submit" value="Search" class="search-button">
</form>
EOF;
if(isset($_GET['search'])) {
$url = site_url() . 'search/' . $_GET['search'];
header ("Location: $url");
}
}
// The not found error // The not found error
function not_found(){ function not_found(){
error(404, render('404', null, false)); error(404, render('404', null, false));


+ 17
- 0
themes/clean/css/style.css View File

@ -366,6 +366,23 @@ aside .copyright p{
margin: 5px 0; margin: 5px 0;
} }
/*-------------------------
Raleted posts
--------------------------*/
.related {
font-size: 14px;
font-family: 'Open Sans Condensed',sans-serif;
width:100%;
float:left;
margin-bottom: 1em;
}
.related ul {
margin-top:0;
margin-bottom: 1em;
}
/*---------------------------- /*----------------------------
Pagination buttons Pagination buttons
-----------------------------*/ -----------------------------*/


+ 1
- 0
themes/clean/post.html.php View File

@ -34,6 +34,7 @@
<?php endif;?> <?php endif;?>
<?php endif;?> <?php endif;?>
</div> </div>
<?php if ($type == 'blogpost'):?><?php echo get_related($p->tag)?><?php endif;?>
<?php if ($type == 'blogpost'):?> <?php if ($type == 'blogpost'):?>
<div class="postnav"> <div class="postnav">
<?php if (!empty($next)):?> <?php if (!empty($next)):?>


+ 50
- 1
themes/default/css/style.css View File

@ -431,6 +431,27 @@ h1.title-post a:hover, h2.title-index a:hover {
width:100%; width:100%;
} }
/*-------------------------
Raleted posts
--------------------------*/
.related {
font-size: 14px;
font-family: 'Open Sans',sans-serif;
width:100%;
float:left;
margin-bottom: 1em;
}
.related h4 {
margin-top: 0;
}
.related ul {
margin-top:0;
margin-bottom: 1em;
}
/*------------------------- /*-------------------------
Pagination + Postnav Pagination + Postnav
--------------------------*/ --------------------------*/
@ -449,7 +470,6 @@ h1.title-post a:hover, h2.title-index a:hover {
border-radius: 3px; border-radius: 3px;
color: #555555; color: #555555;
line-height: 1; line-height: 1;
padding: 10px 20px;
text-align: center; text-align: center;
} }
@ -461,10 +481,39 @@ h1.title-post a:hover, h2.title-index a:hover {
.postnav .newer { .postnav .newer {
float:left; float:left;
margin-right:1em; margin-right:1em;
padding: 10px 15px 10px 25px;
} }
.postnav .older { .postnav .older {
float:right; float:right;
padding: 10px 25px 10px 15px;
}
.postnav .pagination-arrow{
display: inline-block;
border-radius: 3px;
color: #555 !important;
text-decoration: none !important;
text-transform: none;
position: relative;
}
.postnav .pagination-arrow.newer:before,
.postnav .pagination-arrow.older:before{
content: '';
border: 5px solid #555;
border-color: transparent #555 transparent transparent;
width: 0;
height: 0;
position: absolute;
left: 5px;
top: 12px;
}
.postnav .pagination-arrow.older:before{
left:auto;
right:5px;
border-color: transparent transparent transparent #555;
} }
.pager { .pager {


+ 1
- 0
themes/default/post.html.php View File

@ -34,6 +34,7 @@
<?php endif;?> <?php endif;?>
<?php endif;?> <?php endif;?>
</div> </div>
<?php if ($type == 'blogpost'):?><?php echo get_related($p->tag)?><?php endif;?>
<?php if ($type == 'blogpost'):?> <?php if ($type == 'blogpost'):?>
<div class="postnav"> <div class="postnav">
<?php if (!empty($next)):?> <?php if (!empty($next)):?>


Loading…
Cancel
Save