mirror of
https://github.com/danpros/htmly.git
synced 2026-04-21 13:06:22 +05:30
Add related posts
Add related posts feature base on post tag.
This commit is contained in:
parent
f51f27d4d9
commit
7d914fc898
6 changed files with 119 additions and 16 deletions
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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 '<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
|
||||
// to show the previous buttons
|
||||
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
|
||||
function get_menu() {
|
||||
|
||||
$posts = get_spage_names();
|
||||
ksort($posts);
|
||||
krsort($posts);
|
||||
|
||||
echo '<ul>';
|
||||
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
|
||||
function not_found(){
|
||||
error(404, render('404', null, false));
|
||||
|
|
|
|||
|
|
@ -366,6 +366,23 @@ aside .copyright p{
|
|||
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
|
||||
-----------------------------*/
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
<?php endif;?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<?php if ($type == 'blogpost'):?><?php echo get_related($p->tag)?><?php endif;?>
|
||||
<?php if ($type == 'blogpost'):?>
|
||||
<div class="postnav">
|
||||
<?php if (!empty($next)):?>
|
||||
|
|
|
|||
|
|
@ -431,6 +431,27 @@ h1.title-post a:hover, h2.title-index a:hover {
|
|||
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
|
||||
--------------------------*/
|
||||
|
|
@ -449,7 +470,6 @@ h1.title-post a:hover, h2.title-index a:hover {
|
|||
border-radius: 3px;
|
||||
color: #555555;
|
||||
line-height: 1;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
|
@ -461,10 +481,39 @@ h1.title-post a:hover, h2.title-index a:hover {
|
|||
.postnav .newer {
|
||||
float:left;
|
||||
margin-right:1em;
|
||||
padding: 10px 15px 10px 25px;
|
||||
}
|
||||
|
||||
.postnav .older {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
<?php endif;?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
<?php if ($type == 'blogpost'):?><?php echo get_related($p->tag)?><?php endif;?>
|
||||
<?php if ($type == 'blogpost'):?>
|
||||
<div class="postnav">
|
||||
<?php if (!empty($next)):?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue