Hi, I'm looking to add a short snippet of code to every node of an existing site. My approach thus far has been to edit node.tpl.php, to place the item like this:

 <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) {
      print $picture;
    }?>
<ITEM GOES HERE>
    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
<hr>
    <div class="content"><?php print $content?></div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>

When viewing an individual node, this puts the item just below the node title, which is fine.
Example: http://www.websenior.org/node/7705

But my issue is that this approach also displays the item multiple times on category view pages that list the teaser for multiple nodes, which is not desirable.
Example: http://www.websenior.org/nursing-homes-in-louisiana

So what I want is for the item to appear on the node page but NOT on the list page. Much obliged for any help.

Jack

Comments

zbricoleur’s picture

The $page variable is available to node.tpl.php. It will be set to true if the node is being displayed by itself (i.e., on a page of its own).

http://drupal.org/node/11816

sovarn’s picture

Wrap the code in:

<?php
if($page){
    //stuff in here
}
?>

This says, if the node being displayed is the full page version then execute the code.

2houseplague’s picture

Conditional approach makes perfect sense, but the code returned an error on line 6, "unexpected '<'"...

sovarn’s picture

do this instead.

<?php
if($page) :
?>
   <div>HTML IN HERE</div>
<?php
endif; }
?>

koneru.46@gmail.com’s picture

The paranthesis "}" is not required.delete it,and the code should work fine.It should be

<?php
if($page) :
?>
   <div>HTML IN HERE</div>
<?php
endif; 
?>
sovarn’s picture

oh yeah :p i just copied and pasted it from my previous post and forgot to delete it.

2houseplague’s picture

That works perfectly. Thanks!