In reading a web page, sometimes we want to read the related pages or articles concerned and that they have been published before. Typically, related articles are placed at the beginning or end of an article page. Related articles are placed in a box commonly referred to “related articles”. In this box (see the picture below), there are one or more related articles provided.
Related articles are useful for visitors to navigate a web page to obtain relevant information, which may have been available before, so that visitors do not have to search in a much effort. The following tips will help you in making the related pages box of an article.
Step 1. Open file lib/articles/artlib.php. Copy and paste this below functions into lib/articles/artlib.php
//function to select the category of an identified article - begin
function get_categid_article($articleId) {
$query = "SELECT `tiki_category_objects`.`categId` FROM `tiki_category_objects`
INNER JOIN (`tiki_objects`
INNER JOIN `tiki_articles`
ON `tiki_objects`.`itemId` = `tiki_articles`.`articleId`)
ON `tiki_category_objects`.`catObjectId` = `tiki_objects`.`objectId`
WHERE (`tiki_objects`.`type`='article' and `tiki_articles`.`articleId`= ?)";
return $this->getOne($query, array((int)$articleId));
}
//function to select the category of an identified article – end
//function to list articles in a given category - begin
function list_relatedArticles($offset = 0, $pdate = '', $articleID='', $maxRecords = -1) {
$query = "SELECT `tiki_articles`.* FROM `tiki_categories`
INNER JOIN (`tiki_category_objects`
INNER JOIN (`tiki_objects`
INNER JOIN `tiki_articles`
ON `tiki_objects`.`itemId` = `tiki_articles`.`articleId`)
ON `tiki_category_objects`.`catObjectId` = `tiki_objects`.`objectId`)
ON `tiki_categories`.`categId` = `tiki_category_objects`.`categId`
WHERE (`tiki_objects`.`type`='article' and `tiki_categories`.`categId` = ? and `tiki_articles`.`publishDate` < ? )
order by `tiki_articles`.`publishDate` desc";
$result = $this->query($query,array($this->get_categid_article($articleID),$pdate),$maxRecords,$offset);
$ret = array();
while ($res = $result->fetchRow()) {
$res["entrating"] = floor($res["rating"]);
if (empty($res["body"])) {
$res["isEmpty"] = 'y';
} else {
$res["isEmpty"] = 'n';
}
$ret[] = $res;
}
$retval = array();
$retval["data"] = $ret;
return $retval;
}
//function to list articles in a given category - end
Save and close lib/articles/artlib.php.Step 2. Open /tiki-read_article.php. Copy this script below and paste to /tiki-read_article.php right before script: ask_ticket('article-read');:
// Begin - call related article function in artlib.php, maximu record = 5
$relatedpages = $artlib->list_relatedArticles(0, $article_data['publishDate'],$article_data['articleId'],5);
$smarty->assign_by_ref('relatedpages', $relatedpages["data"]);
// End – call related article function in artlib.php
Save and close /tiki-read_article.php.
Step 3. Make related article box inside the article content. Open /templates/tiki-read_article.tpl. Copy the smarty template script below and paste to /templates/tiki-read_article.tpl:
{if !empty($relatedpages)}
<table style="float:right; margin-right:15px;font-size:95%; padding-top:1px" bordercolor="#5506CF" width="296" border=1 x:str>
<tr>
<th width="292" align="left">
{* Begin - recent article by related article *}
{tr}<strong>Related articles in</strong>{/tr}<br />
<span>
{foreach name=u key=k item=i from=$catp}
<a class="categpath" href="tiki-browse_categories.php?parentId={$k}&deep=on" title="{tr}Browse Category{/tr}">{$i|tr_if|replace:' ':' '}</a>{if !$smarty.foreach.u.last} {$prefs.site_crumb_seper|escape:"html"} {/if}
{/foreach}
</span>
</th>
</tr>
<tr>
<td width="292" align="left">
{section name=listix loop=$relatedpages}
{if $prefs.art_list_title eq 'y'}
<p><a class="link" title="{$relatedpages[listix].heading|escape}" href="{$relatedpages[listix].articleId|sefurl:article}">{$relatedpages[listix].title|escape}</a></p>
{/if}
{sectionelse}
<b>{tr}No article found{/tr}</b>
{/section}
<br />
{* End - recent article by related article *}
</td>
</tr>
</table>
{/if}
You can paste the above scripts right after this script: {include file='comments.tpl'} or before this script: {$parsed_heading}. Save and close /templates/tiki-read_article.tpl. <table style="float:right; margin-right:15px;font-size:95%; padding-top:1px" bordercolor="#5506CF" width="296" border=1 x:str>
<tr>
<th width="292" align="left">
{* Begin - recent article by related article *}
{tr}<strong>Related articles in</strong>{/tr}<br />
<span>
{foreach name=u key=k item=i from=$catp}
<a class="categpath" href="tiki-browse_categories.php?parentId={$k}&deep=on" title="{tr}Browse Category{/tr}">{$i|tr_if|replace:' ':' '}</a>{if !$smarty.foreach.u.last} {$prefs.site_crumb_seper|escape:"html"} {/if}
{/foreach}
</span>
</th>
</tr>
<tr>
<td width="292" align="left">
{section name=listix loop=$relatedpages}
{if $prefs.art_list_title eq 'y'}
<p><a class="link" title="{$relatedpages[listix].heading|escape}" href="{$relatedpages[listix].articleId|sefurl:article}">{$relatedpages[listix].title|escape}</a></p>
{/if}
{sectionelse}
<b>{tr}No article found{/tr}</b>
{/section}
<br />
{* End - recent article by related article *}
</td>
</tr>
</table>
{/if}
Step 4. Finish. Now you can open any article available with the related articles box

No comments:
Post a Comment