Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By oziumjinx on
Im having some difficulty telling the Similar Entries module to display only one specific type of content. As I'm somewhat new to PHP, Im not sure where in the module code I should specify my content type. Below is the code for the Similar Entries module. If someone can be kind enough to point out where I place my content type, I would appreciate it.
<?php
/**
* @file
* Module that shows a block listing similar entries.
* NOTE: USES MySQL's FULLTEXT indexing.
* http://arnab.org/project/similar
*/
$similar_node_title = "";
$similar_node_body = "";
$similar_node_nid = "";
/**
* Implementation of hook_help().
*/
function similar_help($section = "admin/help#similar") {
switch ($section) {
case "admin/help#similar":
return t("<p>Lists 10 most similar nodes to the current node.</p>");
case "admin/modules#description":
return t("Lists 10 most similar nodes to the current node.");
case 'node/add#similar':
return t("Lists 10 most similar nodes to the current node.");
break;
}
}
/**
* Implementation of hook_menu().
*/
function similar_menu() {
global $similar_node_title;
global $similar_node_body;
global $similar_node_nid;
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)));
if ($node->nid) {
$similar_node_title = $node-> title;
$similar_node_body = $node-> body;
$similar_node_nid = $node-> nid;
}
}
}
/**
* Implementation of hook_block().
*
* This hook both declares to Drupal what blocks are provided by the module, and
* generates the contents of the blocks themselves.
*/
function similar_block($op = 'list', $delta = 0) {
global $similar_node_nid;
// The $op parameter determines what piece of information is being requested.
if ($op == 'list') {
// If $op is "list", we just need to return a list of block descriptions. This
// is used to provide a list of possible blocks to the administrator.
$blocks[0]['info'] = t('Similar Entries');
return $blocks;
}
else if ($op == 'view') {
// If $op is "view", then we need to generate the block for display purposes.
// The $delta parameter tells us which block is being requested.
if ($similar_node_nid > 0) {
switch ($delta) {
case 0:
// The subject is displayed at the top of the block. Note that it should
// be passed through t() for translation.
$block['subject'] = t('Similar Entries');
// The content of the block is typically generated by calling a custom
// function.
$block['content'] = _similar_content();
}
}
return $block;
}
}
Thanks,
-=Vince