Guest User

Untitled

a guest
Jul 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.87 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 class="topContributors" style="float:left;">' . "\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. $('.callout ul').each(function(){
  59.   if ($(this).children('li').length > 3) {
  60.     // Add a wrapper div and split into two lists, and float them using CSS.
  61.     listElements = $(this).children('li');
  62.     leftColumn = listElements.slice(0, Math.ceil(listElements.length / 2)).clone();
  63.     rightColumn = listElements.slice(Math.ceil(listElements.length / 2)).clone();
  64.     $(this).wrap('<div class="no-css3-columns">');
  65.     parentDiv = $(this).parent('.no-css3-columns');
  66.     $(this).remove(); // delete the < ul >
  67.     $(leftColumn).appendTo(parentDiv).wrapAll('<ul />');
  68.     $(rightColumn).appendTo(parentDiv).wrapAll('<ul />');
  69.   }
  70. });
  71. </script>
  72. <?php
  73.         echo $after_widget;
  74.     }
  75.  
  76.     /**
  77.      * Sanitize widget form values as they are saved.
  78.      * @see WP_Widget::update()
  79.      * @param array $new_instance Values just sent to be saved.
  80.      * @param array $old_instance Previously saved values from database.
  81.      * @return array Updated safe values to be saved.
  82.      */
  83.     public function update( $new_instance, $old_instance ) {
  84.         $instance = array();
  85.         $instance['title'] = strip_tags( $new_instance['title'] );
  86.  
  87.         return $instance;
  88.     }
  89.    
  90.     /**
  91.      * Back-end widget form.
  92.      * @see WP_Widget::form()
  93.      * @param array $instance Previously saved values from database.
  94.      */
  95.     public function form( $instance ) {
  96.         if ( isset( $instance[ 'title' ] ) ) {
  97.             $title = $instance[ 'title' ];
  98.         }
  99.         else {
  100.             $title = __( 'Jquery Top Contributors', 'text_domain' );
  101.         }
  102.         ?>
  103.         <p>
  104.         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  105.         <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 ); ?>" />
  106.         </p>
  107.         <?php
  108.     }
  109.  
  110. } // class Top_Contributors
  111. add_action( 'widgets_init', create_function('', 'return register_widget("Jquery_Top_Contributors");') );
Add Comment
Please, Sign In to add comment