Adding OG Group name to group posts in Drupal

by Mike Richardson on February 8, 2010

in Code, Drupal

Out of the box, the Drupal Organic Groups module doesn’t put the group name at the top of each group post. This looked a bit odd to use because we use a modified og_tracker block on our homepage to show registered users new group, blog and comment content.

When you clicked on the title of the group post from this block you didn’t really have a context in terms of which group you were in (apart from the not so conspicuous group tools block in the right sidebar.

A quick template override was needed. Here’s what I did:

  • first I copied node.tpl.php to node-og-group-post.tpl.php in our sites/all/themes/custom/begrand960 directory (the actual directory will depend on your sites default template, ours is called begrand960)
  • edited node-og-group-post.tpl.php and added the following code (just after <?php print $picture ?>)…

if ($node->og_groups && $page) {
$currentGroup = og_get_group_context();
print "

";
print $currentGroup->og_description."

";
}

The og_get_group_context() function returns an array with lot’s of useful information. As always, you can dump the contents of an array in php by using:

print "

";
print_r($arrayName);
print "

";

Don’t forget to make sure you put the code inside existing php tags!

Hey presto! Nicely formatted link back to the parent group that only displays on the post page and not the group summary. Which is nice.

Bookmark and Share

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

{ 1 comment… read it below or add one }

1 BeGrandTech February 16, 2010 at 10:05 pm

Error in my original post.

$currentGroup->og_description

should be

$currentGroup->title

Doh!

Reply

Leave a Comment

Previous post: Do you need a bug tracker?

Next post: Anatomy of an Iteration