Adding a See Also to a content type

While taxonomy and views can be used prived a list of related entries, it lacks the ability for the author to select individual related entries. Such as writing a short series over time and wanting each in the series to display links to the others.

For this purpose I added a new field Node reference to allow the author to add as many references to existing nodes as needed.

Adding a node reference field to content type

Now we need to edit the node-type.tpl.php to see if there are any see also links and display them.

I have placed this within the content div as I want this area to float to the left of the entry it is in.

<?php
// we only want this to appear within the full page view      
if ($page != 0){
    $see_also_count = count($node->field_see_also); //Drupal seems to return a count of 1 even when there are 0
    if ($see_also_count>0 && strlen($node->field_see_also[0]['view'])>0){
      print '<div class="seealso"><h3>See Also</h3><ul>';
      foreach ($node->field_see_also as $see_also){
        echo '<li>' . $see_also['view'] . '</li>';
      }
      print '</ul></div>';
    }
      }
    ?>

Then adding the style for this div to my css

div.seealso{
width:200px;
float:right;
border:1px solid #999;
padding:3px;
margin:3px;
}

 

Adding a See Also node reference

 

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.