Sorry, this page is only available in one language

MoreLikeThis

Suggested dropletname: MoreLikeThis

Published by: Dev4me

This Droplet creates a list of pages that will have one or more similar keywords in the page settings.

// This droplet returns a list of pages with at least one of the keywords as the current page.
// Keywords are set in the page settings.
global $database, $wb;
//Build the output
$returnprefix = "<div id='likethese'><b>More pages like this</b><br/><ul>";
$returnending = "</ul></div>";
$returndata = "";
// Get keyword list of the current page
$query=$database->query("SELECT keywords FROM ".TABLE_PREFIX."pages where page_id=".PAGE_ID);
$keyword=$query->fetchRow();
$myKeywords = array_map("trim",explode(",",strtolower($keyword["keywords"])));
// Get keywords of all other pages
$query=$database->query("SELECT * FROM ".TABLE_PREFIX."pages where page_id!=".PAGE_ID." AND keywords != ''");
while ($thepage = $query->fetchRow()) {
    if($wb->show_page($thepage)) {
        $pageKeywords = array_map("trim",explode(",",strtolower($thepage['keywords'])));
        $sameKeywords = array_intersect($myKeywords,$pageKeywords);
        if (count($sameKeywords) > 0) 
            $returndata .= '<li><a href="' . $wb->page_link($thepage['link']) . '">' . $thepage['menu_title'] . '</a></li>';
    }
}
if ($returndata)
    return $returnprefix.$returndata.$returnending;
else
    return " ";  //something must be returned! Just return a whitespace

The keyword meta tag is normally used for searchengines, but this Droplet shows it can be used for simple page tagging too.
The Droplet compares the comma seperated list of keywords in the current page to the keywords of all other pages. If one of the keywords match the current page, that page (url) will be added to the output list.



« Previous droplet | Overview |