The Joomla! Forum ™






Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Nov 17, 2005 11:44 am 
User avatar
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Oct 06, 2005 2:02 pm
Posts: 3
Location: Australia
Hi,

The code on this page of the developers manual did not work for me. I've made some changes to the example module .php to make it functional.

The revised code follows.

regards,
affect


Code:
<?php
//Related Content//
/**
* Related Content Module
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
 
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
 
$option = trim( mosGetParam( $_REQUEST, 'option', null ) );
$task = trim( mosGetParam( $_REQUEST, 'task', null ) );
$id = intval( mosGetParam( $_REQUEST, 'id', null ) );
$itemid = intval(mosGetParam( $_REQUEST,'Itemid',null));

if ($option == 'com_content' && $task == 'view' && $id) {

 // select the meta keywords from the item
 $query = "SELECT metakey FROM #__content WHERE id='$id'";
 $database->setQuery( $query );

 if ($metakey = trim( $database->loadResult() )) {
  // explode the meta keys on a comma
  $keys = explode( ',', $metakey );
  $likes = array();

  // assemble any non-blank word(s)
  foreach ($keys as $key) {
   $key = trim( $key );
   if ($key) {
    $likes[] = $key;
   }
  }
  if (count( $likes )) {
   // select other items based on the metakey field 'like' the keys found
  

   $query = " SELECT id, title"
           . " FROM jos_content"
           . " WHERE id<>$id "
           . " AND state=1 "
           . " AND access <=$my->gid "
           . " AND (metakey LIKE '%";
   $query .= implode( "%' OR metakey LIKE '%", $likes );
   $query .= "%')";

   $database->setQuery( $query );
   if ($related = $database->loadObjectList() ) {

    foreach ($related as $item)
     {
     echo "<a href=http://banfield/index.php?option=com_content&task=view"
           . "&id=$item->id&Itemid=$Itemid>$item->title</a><br>";
    }
   }
    echo $database->getErrorMsg();
  }

 }
}

?>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 



Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group