Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: [MOD - WIP] Show keywords in article  (Read 2769 times)

centered

  • Guest
[MOD - WIP] Show keywords in article
« on: June 13, 2007, 03:55:34 AM »

Credit to mpancorbo in this thread: http://www.solucija.com/forum/viewtopic.php?id=2342

0. Backup
0a. Requires this mod: http://www.solucija.com/forum/viewtopic.php?id=637

1.  Add to Language variables:
Code: [Select]
$l['labels'] = 'Tags';2. Add this to Admin Variables:
Code: [Select]
$l['divider'] = ''; //divider character3.  Find this line in // center:
Code: [Select]
if ($article == "" AND strlen($r['text']) > $shorten) { echo "...</p>"; }And place this right afterwards:
Code: [Select]
$labels = explode(',', $r['keywords_meta']);
$first_label = false;
foreach ($labels as $labels) {
    if($labels == '') break;
    if(strtolower($labels) == 'esperanto') continue; // put here your own avoided keyword
    if($first_label == false){
        echo '<p class="tags clear">'.l('labels');
        $first_label = true;
    }
    echo ' '.l('divider').' <a href="index.php?search='.$labels.'">'.$labels.'</a>';
}
if($first_label == true) echo '</p>';
4. Also in Center, find this line:
Code: [Select]
if (isset($_GET['articleid'])) { $articleid = $_GET['articleid']; }after it place this line:
Code: [Select]
if (isset($_GET['search'])) {search_keywords($_GET['search']); $processed = true;}5.  With me so far... ok
Now after the Search Engine add this:
Code: [Select]
//SEARCH ENGINE ONLY ON KEYWORDS_META
function search_keywords($word) {
connect_to_db();
$db = new Database(s('dbname'));
// If Mysql take out the previous 2 lines
    echo '<h2>'.l(search_results).'</h2>';
    $query = "SELECT * FROM ".s('prefix')."articles WHERE published = 1 AND keywords_meta LIKE '%$word%' ORDER BY date DESC'";
    $result = $db->query($query);
while ($r = $result->fetch_array()) {

// If mysql replace the previous 2 lines with the following 2:
//    $result = mysql_query($query);
//      while ($r = mysql_fetch_array($result)) {
$num++;
$date = date(s('date_format'), strtotime($r['date']));
echo "<p><a href='" .s('website'). find_cat_sef($r['category']). "/" .$r['seftitle']. "/'>" .$r['title']. "</a> <img src='" .s('website'). "images/arrow.gif' alt='>' /> " . $date. "</p>";
}
if ($num == "") {
echo "<p>". l('noresults') ." <b> " . $search_query . "</b>.</p>";
$num = "0";
}
else {
echo "
<p><b>" . $num . "</b> ". l('resultsfound') ."<b> " . $search_query . "</b>.</p>";
}
echo "<p>
<a href='" .s('website'). "'>". l('backhome') ."</a></p>";
}
« Last Edit: August 27, 2007, 01:51:27 PM by centered effect »
Logged