Advertisement
MichealKennedy

Top Authors by Post Count Listed in Two Columns - WordPress

Apr 10th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <div class="widget">
  2.         <h4>Top Contributers to Entries</h4>
  3.         <?php
  4.         function top_authors_list($number = 10) {
  5.           $u = array();
  6.           $authors = get_users_of_blog();
  7.           if ($authors) {
  8.             foreach ($authors as $author) {
  9.               $post_count = get_usernumposts($author->user_id);
  10.               $u[$author->user_id] = $post_count;
  11.             }
  12.             arsort($u);
  13.             $i = 0;
  14.             echo '<div class="bg">';
  15.             echo '<ul class="column" style="float:left;margin-right: 56px;">' . "\n";
  16.             foreach ($u as $key => $value) {
  17.               $i++;
  18.               if ($i <= $number) {
  19.                 $user = get_userdata($key);
  20.                 $author_posts_url = get_author_posts_url($key);
  21.                 $post_count = $value;
  22.                 if ($post_count > 0) {
  23.                   echo '<li><a href="' . $author_posts_url .'"><span class="category-list-item">' . $user->display_name . '</span> <span class="menu-count">' . $post_count . '</span></a></li>' . "\n";
  24.                 }
  25.               }
  26.             }
  27.             echo '</ul></div>';
  28.           }
  29.         }
  30.         ?>
  31.         <?php if (function_exists('top_authors_list')) top_authors_list(10); ?>
  32.         <script type="text/javascript">
  33.         jQuery('document').ready(function($) {
  34.           var i = 0;
  35.           var $newUL;
  36.           var $theColumn = $('.column');
  37.           var length = $theColumn.children('li').length;
  38.           while(length > 3) { /* when enough members merits it, change this and others to 15 */
  39.             $newUL = $('<ul class="' + $theColumn.attr('class') + '" style="float:left;"></ul>');
  40.             while(i < 3) {
  41.                 $theColumn.children('li').eq(3).appendTo($newUL)
  42.                 i++;
  43.                 length--;
  44.             }
  45.             $('.bg').append($newUL);
  46.             i = 0;
  47.           }
  48.         });
  49.         </script>
  50.     </div><!--/top contributors-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement