How to Change default Members view to Popular

Hi,

I don't really think this is the right way to do this. What is really needed is a plugin that adds tabs like Alpha and Most Active and allows you to order the tabs and choose the default view.

But all I wanted was for Popular to be the default instead of Newest because the Newest account are often the least interesting.

So I did this.

/**

 * Members page handler

 *

 * @param array $page url segments

 * @return bool

 */

function members_page_handler($page) {

$base = elgg_get_plugins_path() . 'members/pages/members';

 

if (!isset($page[0])) {

$page[0] = 'popular';

}

Where I changed the word newest to popular and it worked.

I'm new to Elgg so any thoughts on this are appreciated.

Thanks,

Hairy Larry

 

 

 

  • @hairylarry

    My own solution for ALWAYS DELETING newest and online members

    Index

    <?php
    /**
     * Members index
     *
     */

    //$num_members = get_number_users();

    $title = elgg_echo('members:label:popular');

    $options = array('type' => 'user', 'full_view' => false, 'limit' =>200,);
    switch ($vars['page']) {
        default:
            $options['relationship'] = 'friend';
            $options['inverse_relationship'] = false;
            $content = elgg_list_entities_from_relationship_count($options);
            break;
        //case 'online':
            //$content = get_online_users();
        //    break;
    //    case 'newest':
    //    default:
        //    $content = elgg_list_entities($options);
            //break;
    }

    $params = array(
        'content' => $content,
        'sidebar' => elgg_view('members/sidebar'),
        'title' => $title,
        'filter_override' => elgg_view('members/nav', array('selected' => 'popular')),
    );

    $body = elgg_view_layout('content', $params);

    echo elgg_view_page($title, $body);

    Navigation:

    <?php
    /**
     * Members navigation
     */

    $tabs = array(
        //'newest' => array(
        //    'title' => elgg_echo('members:label:newest'),
        //    'url' => "members/newest",
        //    'selected' => $vars['selected'] == 'newest',
        //),
        'popular' => array(
            'title' => elgg_echo('members:label:popular'),
            'url' => "members/popular",
            'selected' => $vars['selected'] == 'popular',
        ),
    //    'online' => array(
        //    'title' => elgg_echo('members:label:online'),
        //    'url' => "members/online",
        //    'selected' => $vars['selected'] == 'online',
        //),
    );

    echo elgg_view($tabs);
  • If you are on 1.8, the way of doing it is unregister the members_page_handler() function. Register your own page handler for members page. and copy the pages/index.php to your plugin's pages/index.php \. Change the switch as folllows

    switch ($vars['page']) {
        case 'popular':
            default:
            $options['relationship'] = 'friend';
            $options['inverse_relationship'] = false;
            $content = elgg_list_entities_from_relationship_count($options);
            break;
        case 'online':
            $content = get_online_users();
            break;
        case 'newest':
            $content = elgg_list_entities($options);
            break;
    }

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.