Advertisement
Guest User

Untitled

a guest
Mar 30th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. //widget - top contributors
  2. class Jquery_Top_Contributors extends WP_Widget {
  3.  
  4.     /**
  5.      * Register widget with WordPress.
  6.      */
  7.     public function __construct() {
  8.         parent::__construct(
  9.             'jquery_top_contributors', // Base ID
  10.             'Jquery_Top_Contributors', // Name
  11.             array( 'description' => __( 'Display top contributorz block', 'text_domain' ), ) // Args
  12.         );
  13.     }
  14.  
  15.     /**
  16.      * Front-end display of widget.
  17.      * @see WP_Widget::widget()
  18.      * @param array $args     Widget arguments.
  19.      * @param array $instance Saved values from database.
  20.      */
  21.     public function widget( $args, $instance ) {
  22.         extract( $args );
  23.         $title = apply_filters( 'widget_title', $instance['title'] );
  24.  
  25.         echo $before_widget;
  26.         if ( ! empty( $title ) )
  27.             echo $before_title . $title . $after_title;
  28. ?><?php
  29. function top_authors_list($number = 10) {
  30.   $u = array();
  31.   $authors = get_users_of_blog();
  32.   if ($authors) {
  33.     foreach ($authors as $author) {
  34.       $post_count = get_usernumposts($author->user_id);
  35.       $u[$author->user_id] = $post_count;
  36.     }
  37.     arsort($u);
  38.     $i = 0;
  39.     echo '<div class="call-out">';
  40.     echo '<ul id="columns">' . "\n";
  41.     foreach ($u as $key => $value) {
  42.       $i++;
  43.       if ($i <= $number) {
  44.         $user = get_userdata($key);
  45.         $author_posts_url = get_author_posts_url($key);
  46.         $post_count = $value;
  47.         if ($post_count > 0) {
  48.           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";
  49.         }
  50.       }
  51.     }
  52.     echo '</ul></div>';
  53.   }
  54. }
  55. ?>
  56. <?php if (function_exists('top_authors_list')) top_authors_list(10); ?>
  57. <script>
  58. $j=jQuery.noConflict();
  59. var cols = 2;
  60. var container = $j('ul#columns');
  61. var items = container.find('li');
  62. var itemsPerCol = Math.ceil(items.length / cols);
  63. var stack = [];
  64. for (var i = 0; i < itemsPerCol; i++) {
  65.     for (var k = 0; k < cols; k++) {
  66.     stack.push(items[i + (itemsPerCol * k)]);
  67.     }
  68. }
  69. items.css({
  70.     float:'left',
  71.     width:Math.floor(container.width() / cols)
  72. });
  73.    
  74. container.html(stack).append($j('<br>').css({clear:'both'}));
  75. </script>
  76.  
  77. <?php
  78.         echo $after_widget;
  79.     }
  80.  
  81.     /**
  82.      * Sanitize widget form values as they are saved.
  83.      * @see WP_Widget::update()
  84.      * @param array $new_instance Values just sent to be saved.
  85.      * @param array $old_instance Previously saved values from database.
  86.      * @return array Updated safe values to be saved.
  87.      */
  88.     public function update( $new_instance, $old_instance ) {
  89.         $instance = array();
  90.         $instance['title'] = strip_tags( $new_instance['title'] );
  91.  
  92.         return $instance;
  93.     }
  94.    
  95.     /**
  96.      * Back-end widget form.
  97.      * @see WP_Widget::form()
  98.      * @param array $instance Previously saved values from database.
  99.      */
  100.     public function form( $instance ) {
  101.         if ( isset( $instance[ 'title' ] ) ) {
  102.             $title = $instance[ 'title' ];
  103.         }
  104.         else {
  105.             $title = __( 'Jquery Top Contributors', 'text_domain' );
  106.         }
  107.         ?>
  108.         <p>
  109.         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  110.         <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  111.         </p>
  112.         <?php
  113.     }
  114.  
  115. } // class Top_Contributors
  116. add_action( 'widgets_init', create_function('', 'return register_widget("Jquery_Top_Contributors");') );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement