• Hi Guys,
    I need to sort users of certain role and alphabetically with heading like this way.

    A:
    – Abraham
    – Abby
    – Adam
    B:
    – Ben
    – Bob
    – Billy

    Actually, I have 2 codes, one display users alphabetically with the heading (it works but it shows all users), and another display them by role and alphabetically BUT NO HEADING.

    Here the code 1 ( no role selected) :

    <?php
        $qry = "SELECT DISTINCT wp_users.user_login, wp_users.display_name,
                LEFT(UPPER(wp_users.display_name), 1) AS first_char
                FROM wp_users, wp_usermeta
                WHERE UPPER(wp_users.display_name) BETWEEN 'A' AND 'Z'
                OR wp_users.display_name BETWEEN '0' AND '9'
                AND wp_usermeta.meta_key = 'userphoto_approvalstatus'
                AND wp_usermeta.meta_value = '2'
                AND wp_usermeta.user_id = wp_users.ID
                ORDER BY wp_users.display_name ASC";
                $result = mysql_query($qry);
                $current_char = '';
                while ($row = mysql_fetch_assoc($result)) {
                    if (!isset($current_char)) {
                            echo '<div class="spacer"></div><li class="letter"><div class="letter_head"><h2>'.$current_char.'</h2><a name="'.$current_char.'"></a></div>';
                            echo '<ul class="lisa">';
                    } elseif ($row['first_char'] != $current_char) {
                            echo '</ul>';
                            $current_char = $row['first_char'];
                            echo '<div class="spacer"></div><li class="letter"><div class="letter_head"><h2>'.$current_char.'</h2><a name="'.$current_char.'"></a></div>';
                            echo '<ul class="list">';
                    }
    
                    echo '<li class="letters"><a href="';
                    bloginfo('url');
                    echo'/author/'.$row['user_login'].'">'.$row['display_name'].'</a></li>';
                }
        ?>

    Here the code 2 (Display by role, no heading) :

    <?php
        $blogusers = get_users('blog_id=1&orderby=nicename&role=Contributor');
        foreach ($blogusers as $user) {
            echo '<li class="letters"><a href="';
                    bloginfo('url');
                    echo'/author/'. $user->display_name .'">' . $user->display_name . '</a></li>';
        }
    ?>

    So somehow, I need both codes to work together, the list I need must be alphabetically displayed of a certain role(Contributor) and with the headings.

    I hope someone here can help me to resolve this, your support will be greatly appreciated.

    Thanks guys.

  • The topic ‘Soft list of users of a role alphabetically with heading’ is closed to new replies.