Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //widget - top contributors
- class Jquery_Top_Contributors extends WP_Widget {
- /**
- * Register widget with WordPress.
- */
- public function __construct() {
- parent::__construct(
- 'jquery_top_contributors', // Base ID
- 'Jquery_Top_Contributors', // Name
- array( 'description' => __( 'Display top contributorz block', 'text_domain' ), ) // Args
- );
- }
- /**
- * Front-end display of widget.
- * @see WP_Widget::widget()
- * @param array $args Widget arguments.
- * @param array $instance Saved values from database.
- */
- public function widget( $args, $instance ) {
- extract( $args );
- $title = apply_filters( 'widget_title', $instance['title'] );
- echo $before_widget;
- if ( ! empty( $title ) )
- echo $before_title . $title . $after_title;
- ?><?php
- function top_authors_list($number = 10) {
- $u = array();
- $authors = get_users_of_blog();
- if ($authors) {
- foreach ($authors as $author) {
- $post_count = get_usernumposts($author->user_id);
- $u[$author->user_id] = $post_count;
- }
- arsort($u);
- $i = 0;
- echo '<div class="call-out">';
- echo '<ul class="topContributors" style="float:left;">' . "\n";
- foreach ($u as $key => $value) {
- $i++;
- if ($i <= $number) {
- $user = get_userdata($key);
- $author_posts_url = get_author_posts_url($key);
- $post_count = $value;
- if ($post_count > 0) {
- 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";
- }
- }
- }
- echo '</ul></div>';
- }
- }
- ?>
- <?php if (function_exists('top_authors_list')) top_authors_list(10); ?>
- <script>
- $('.callout ul').each(function(){
- if ($(this).children('li').length > 3) {
- // Add a wrapper div and split into two lists, and float them using CSS.
- listElements = $(this).children('li');
- leftColumn = listElements.slice(0, Math.ceil(listElements.length / 2)).clone();
- rightColumn = listElements.slice(Math.ceil(listElements.length / 2)).clone();
- $(this).wrap('<div class="no-css3-columns">');
- parentDiv = $(this).parent('.no-css3-columns');
- $(this).remove(); // delete the < ul >
- $(leftColumn).appendTo(parentDiv).wrapAll('<ul />');
- $(rightColumn).appendTo(parentDiv).wrapAll('<ul />');
- }
- });
- </script>
- <?php
- echo $after_widget;
- }
- /**
- * Sanitize widget form values as they are saved.
- * @see WP_Widget::update()
- * @param array $new_instance Values just sent to be saved.
- * @param array $old_instance Previously saved values from database.
- * @return array Updated safe values to be saved.
- */
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = strip_tags( $new_instance['title'] );
- return $instance;
- }
- /**
- * Back-end widget form.
- * @see WP_Widget::form()
- * @param array $instance Previously saved values from database.
- */
- public function form( $instance ) {
- if ( isset( $instance[ 'title' ] ) ) {
- $title = $instance[ 'title' ];
- }
- else {
- $title = __( 'Jquery Top Contributors', 'text_domain' );
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
- <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 ); ?>" />
- </p>
- <?php
- }
- } // class Top_Contributors
- add_action( 'widgets_init', create_function('', 'return register_widget("Jquery_Top_Contributors");') );
Add Comment
Please, Sign In to add comment