Community Documentation

Add og group name and author to node

Last updated August 23, 2009. Created by rfay on November 21, 2008.
Edited by SLIU, jhodgdon, lsabug. Log in to edit this page.

This is to include the name of the author of a node and the group the node belongs to. From christefano's post at Drupal Groups: http://groups.drupal.org/node/15751.

Add the following code to the node type template in your theme folder.

<?php if ($submitted): ?>
  <?php if ($og_groups): ?>
  <!-- the post is submitted to a group -->
    <?php
      $og_projects
= array();
      foreach (
$node->og_groups_both as $key => $name) {
       
$og_projects[] = l($name,'node/'.$key,array('class'=>'group'));
      }
     
$og_projects = implode(', ',$og_projects);
   
?>
         
    <span class="submitted">
      <?php print $submitted ?>
      <?php print $og_projects; ?>
    </span>
    <?php elseif (!$og_groups): ?>
    <!-- the post is not submitted to a group -->
    <span class="submitted">
      <?php print $submitted ?>
    </span>
  <?php endif; ?>
<?php endif; ?>

The output will look like this:

Submitted by lsabug on November 20, 2008 - 3:29pm. For Testing Classroom blog

Comments

Hi does this work for drupal

Hi does this work for drupal 6? I was just wanting to put the groups a node belongs to in the teaser view.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 5.x

Theming Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here