I have a view that shows the top-rated nodes by all authors. My problem is that it sometimes gets swamped with nodes all by the same author. How can I only show 1 post per author in my view?

Comments

norio’s picture

*bump* Anyone?

norio’s picture

This is what I've tried so far (in views_user.inc) to fix the problem myself but it's not even showing up in the Views UI...

After this...

    'filters' => array(
      'uid' => array(
        'name' => t('Node: Author Name'),
        'operator' => 'views_handler_operator_or',
        'list' => 'views_handler_filter_username',
        'value-type' => 'array',
        'help' => t('This allows you to filter by a particular user. You might not find this useful if you have a lot of users.'),
      ),

I added this...

      'userdistinct' => array(
        'name' => t('User: Distinct'),
        'operator' => array('=' => 'is'),
        'list' => array('distinct' => 'distinct'),
        'handler' => 'views_handler_filter_distinct_user',
        'value-type' => 'array',
        'help' => t('This filter ensures that only one node per user is listed.'),
      ),

And, later on, I added this...

function views_handler_filter_distinct_user($op, $filter, $filterinfo, &$query) {
  if (!$query->no_distinct) {
    $query->set_distinct();
    $query->add_groupby('node.uid');
  }
}

I took the inspiration for the above bits of code from views_node.inc.

Help?