Delivering a great experience for visitors is an important factor for long term success. Here's a tip along with code, that can help improve the length of your visitors stay.
The Related Content Feature
A visitor goes to a search engine and lands on your site. She reads your content and is looking for more. If you don't have content of interest she hits the back button.
Let's stop that.
One thing you can do is add related content to add to the visitor's experience. Your site must be setup with some sort of categorization feature.
Under Drupal, we can use the taxonomy module. When an article is posted, the author chooses the best category the content is related to. By doing this, we can generate a list of links of the same category.
Create a template.php file and add the following code:
function blued_preprocess_node(&$variables) { /* taxonomy hook to show comma separated terms */ if (module_exists('taxonomy')) { $variables['termLinks'] = ""; $count = 1; $termLinks = taxonomy_link("taxonomy terms", $variables['node']); $numCount = count($termLinks); if ($numCount > 0) { foreach ($termLinks as $linkItem) { $variables['termLinks'] .= l($linkItem['title'], $linkItem['href'], $linkItem); if ($count < $numCount) { $variables['termLinks'] .= ", "; $count++; } } } }
function blued_preprocess_page(&$variables) { // Generate taxonomy terms as a CSV $directory = $variables['directory']; if (module_exists('taxonomy')) { /* generate comma separated terms */ $variables['termCSV'] = ""; $count = 1; $termLinks = taxonomy_link("taxonomy terms", $variables['node']); $numCount = count($termLinks); if ($numCount > 0) { foreach ($termLinks as $linkItem) { $variables['termCSV'] .= $linkItem['title']; if ($count < $numCount) { $variables['termCSV'] .= ", "; $count++; } } } } }
To generate the related links use this code in your page template.
function GetRelatedLinks($node, $numNodes=3) { $output = ""; $terms = taxonomy_node_get_terms($node); foreach($terms as $term){ $sql = "SELECT DISTINCT n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.status = 1 AND tn.tid = ". $term->tid ." AND n.nid != ". $node->nid ." ORDER BY n.created DESC LIMIT $numNodes"; $result = db_query(db_rewrite_sql($sql)); $output .= "<h3>{$term->name}</h3>"; $output .= node_title_list($result); } return($output); }
The best place to create this related links list is in a sidebar or just below the article content. You want to make this list noticeable to the visitor and treat it to say "here is some more stuff for you to look at".