Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this function in Wordpress that counts 10 users by default. I would like to change it from showing 10 users to infinite number. There should be no end to counting. How can I do this?

function get_random_followers($userid, $count = 10){

$followers = get_the_author_meta('followers', $userid);

/** if no followers at the moment */
if( !is_array($followers)){
    $return = "";
} else {

    $flw = array_pick($followers, $count);

    $return = '<ul class="widget_follow">' . "\n";
    foreach( $flw as $folow){

        $return .= "<li>";
            $return .= '<a href="' . get_author_posts_url($folow) . '" title="' . get_the_author_meta('display_name', $folow) . '">';
                if( get_the_author_meta( 'user_custom_avatar', $folow ) != "" ) {
                    $return .= '<img src="' . get_the_author_meta( 'user_custom_avatar', $folow ) . '" alt="" />';
                } else {
                    $return .= get_avatar( get_the_author_meta( 'user_email', $folow ), '40' );
                }
            $return .= '</a>';
        $return .= "<li>";

    }
    $return .= '</ul>' . "\n";
}

echo $return;

}
share|improve this question
    
That looks like a custom function. Would you go ahead and include the function in the code? –  Jonathan Wold Mar 1 '12 at 23:30
    
Just edited the question, thanks :) –  jimilesku Mar 1 '12 at 23:34
4  
Not sure how this is a WP question ... you're using custom functionality and regular old PHP loops. –  EAMann Mar 1 '12 at 23:40
    
Is it possible to add a pagination so when it lists for example 50 followers, to skip to page 2? I have a custom pagination <?php user_pagenavi(); ?> How do I do it? –  jimilesku Mar 2 '12 at 9:09
add comment

1 Answer

up vote 2 down vote accepted

This looks like a custom function.

It's passing $count to a function called array_pick() to limit the size of your follower array. It also looks like array_pick() is a custom function.

But you can easily stop the function from limiting your count by removing the call to array_pick():

function get_random_followers($userid, $count = 10){

    $followers = get_the_author_meta('followers', $userid);

    /** if no followers at the moment */
    if( !is_array($followers)){
        $return = "";
    } else {

        $return = '<ul class="widget_follow">' . "\n";
        foreach( $followers as $folow){

            $return .= "<li>";
                $return .= '<a href="' . get_author_posts_url($folow) . '" title="' . get_the_author_meta('display_name', $folow) . '">';
                    if( get_the_author_meta( 'user_custom_avatar', $folow ) != "" ) {
                        $return .= '<img src="' . get_the_author_meta( 'user_custom_avatar', $folow ) . '" alt="" />';
                    } else {
                        $return .= get_avatar( get_the_author_meta( 'user_email', $folow ), '40' );
                    }
                $return .= '</a>';
            $return .= "<li>";

        }
        $return .= '</ul>' . "\n";
    }

    echo $return;

}

Instead of turning $followers into a 10-item subset ($flw in your example), we loop through the entire $followers collection.

share|improve this answer
    
Thank You very much :) –  jimilesku Mar 2 '12 at 8:28
    
Is it possible to add a pagination so when it lists for example 50 followers, to skip to page 2? I have a custom pagination <?php user_pagenavi(); ?> How do I do it? –  jimilesku Mar 2 '12 at 8:48
1  
Open a new question for that. It's a separate issue. –  EAMann Mar 2 '12 at 14:32
    
I will do as You say :9 Thank You for Your giant help! –  jimilesku Mar 2 '12 at 16:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.