$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
$show_images = isset($instance['images']) ? $instance['images'] : true;
$category = isset($instance['category']) ? $instance['category'] : false;
-
- if ( is_admin() && !$category ) {
- // Display All Links widget as such in the widgets screen
- echo $before_widget . $before_title . _x('All Links', 'links widget') . $after_title . $after_widget;
- return;
- }
+ $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
+ $order = $orderby == 'rating' ? 'DESC' : 'ASC';
+ $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
wp_list_bookmarks(apply_filters('widget_links_args', array(
'category_before' => $before_widget, 'category_after' => $after_widget,
'show_images' => $show_images, 'show_description' => $show_description,
'show_name' => $show_name, 'show_rating' => $show_rating,
- 'category' => $category, 'class' => 'linkcat widget'
+ 'category' => $category, 'class' => 'linkcat widget',
+ 'orderby' => $orderby, 'order' => $order,
+ 'limit' => $limit,
)));
}
function update( $new_instance, $old_instance ) {
$new_instance = (array) $new_instance;
- $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
+ $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
foreach ( $instance as $field => $val ) {
if ( isset($new_instance[$field]) )
$instance[$field] = 1;
}
- $instance['category'] = intval($new_instance['category']);
+
+ $instance['orderby'] = 'name';
+ if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
+ $instance['orderby'] = $new_instance['orderby'];
+
+ $instance['category'] = intval( $new_instance['category'] );
+ $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
return $instance;
}
function form( $instance ) {
//Defaults
- $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
- $link_cats = get_terms( 'link_category');
+ $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
+ $link_cats = get_terms( 'link_category' );
+ if ( ! $limit = intval( $instance['limit'] ) )
+ $limit = -1;
?>
<p>
- <label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
+ <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
<option value=""><?php _ex('All Links', 'links widget'); ?></option>
<?php
. '>' . $link_cat->name . "</option>\n";
}
?>
- </select></p>
+ </select>
+ <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
+ <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
+ <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
+ <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
+ <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
+ <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _e( 'Random' ); ?></option>
+ </select>
+ </p>
<p>
<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
</p>
+ <p>
+ <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
+ <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
+ </p>
<?php
}
}
<li><?php wp_loginout(); ?></li>
<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
<li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
- <li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
+ <li><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>"><?php
+ /* translators: meta widget link text */
+ _e( 'WordPress.org' );
+ ?></a></li>
<?php wp_meta(); ?>
</ul>
<?php
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
$number = 10;
- $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
+ $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
if ($r->have_posts()) :
?>
<?php echo $before_widget; ?>
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
$number = 5;
- $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) );
+ $comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );
$output .= $before_widget;
if ( $title )
$output .= $before_title . $title . $after_title;
unset($rss);
}
-
-
/**
* Display RSS widget options form.
*
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
<p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
- <?php foreach ( get_object_taxonomies('post') as $taxonomy ) :
+ <?php foreach ( get_taxonomies() as $taxonomy ) :
$tax = get_taxonomy($taxonomy);
if ( !$tax->show_tagcloud || empty($tax->labels->name) )
continue;