Super simple question here. I need to be able to print the member count for a group in a custom node tpl and in a custom block, showing group information. Is there a function that I can call to return the member count?

Thanks..

Comments

OpenChimp’s picture

Title: How do I print Member Count » How to OG Member Count in node or block

updating title

OpenChimp’s picture

Title: How to OG Member Count in node or block » How to print OG Member Count in node or block

It seems that there is a views field handler for printing the member count but I do not see any simple way of retrieving this information without the use of a view.

It seems to me that the member count should be added to the group node data so it can be easily accessed during theming.

What is the best method for getting this info? Do we have to write a query to read it out of the database, as is done by the views handler?

class og_views_handler_field_og_member_count extends views_handler_field_numeric {
  function query() {
    $table = $this->query->ensure_table('og');
    $sql = og_list_users_sql(1, 0, NULL, TRUE);
    $sql = str_replace('%d', 'og.nid', $sql);
    $this->query->add_field('', "($sql)", 'member_count');
    $this->field_alias = 'member_count';
  }
  
  function render($values) {
    $nid = $values->nid;
    $txt = $values->member_count;
    if (og_is_group_member($nid)) {
      $value = og_is_picture() ? l($txt, "og/users/$nid/faces") : l($txt, "og/users/$nid");
      return check_plain($this->options['prefix']) . $value . check_plain($this->options['suffix']);
    }
    else {
      return parent::render($values);
    }
  }
}
gokulnk’s picture

Copy paste this code into block and select Input type as php.

  if(arg(0) == 'node' && is_numeric(arg(1))){
  $node = node_load(arg(1));
  list($txt, $subscription) = og_subscriber_count_link($node);
  print($txt);
  }
zmove’s picture

Issue summary: View changes

How to do that in the recent version of og, this function doesn't exist anymore.