Download & Extend

hack that hyperlinks author(s)

Project:Amazon associate tools
Version:5.x-1.5
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I'm not sure if this is the correct place to post this, but I added a small hack to amazon tools. It adds a hyperlink to all author names within a book node; as a result, each author's name links to an advanced site search, and when selected will search for the author's name within all other amazon nodes. This way, if a user is viewing a book by a particular author, they can easily search your site for other books by the same author.

Around line 1455 in amazon.module, look for this code:

if ($node->author) {
   $output .= 'author: ' . implode('<br />', $node->author) . '<br />';
}

Replace it with the following code:
if ($node->author) {
  $i = 0;
  if ($node->author[$i+1]) { $output .= 'authors: '; }
    else { $output .= 'author: '; } 
  while ($node->author[$i]) {
  $output .= '<a href = "';
$output .= base_path() . "search/node/" . $node->author[$i];
$output .= '+type%3Aamazon_node">';
$output .= $node->author[$i];
if ($node->author[$i+1]) { $output .= '</a>, '; }
    else { $output .= '</a><br />'; }
      $i++;
}
}

If there is one author listed, the result will look like this:
author: Stephen King
If there are multiple authors, the result will look like this:
authors: Stephen King, Anne Rice, Aristotle
... and each author will be a separate link to an advanced amazon node search for the author's name.

Brad

Comments

#1

If you want to do an exact site search for a name, change:

$output .= base_path() . "search/node/" . $node->author[$i];

To this:

$output .= base_path() . "search/node/%22" . $node->author[$i] . "%22";

If you do this, it will return matches specifically for "Stephen King" rather than "Stephen King" "Stephen" and "King" which is what the original code will return.

nobody click here