Changeset 816887
- Timestamp:
- 12/08/2013 02:38:50 PM (12 years ago)
- Location:
- featured-posts-widget/trunk
- Files:
-
- 2 added
- 2 edited
-
css (added)
-
css/featured-posts-widget.css (added)
-
featured-posts-widget.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
featured-posts-widget/trunk/featured-posts-widget.php
r573986 r816887 5 5 Description: Add featured posts to a widget 6 6 Author: Tom Singer 7 Version: 0.17 Version: 1.0 8 8 Author URI: http://www.89pies.com 9 9 License: MIT … … 23 23 24 24 $this->WP_Widget('featured_posts_widget', 'Featured Posts', $widget_ops, $control_ops ); 25 26 25 27 } 26 28 27 29 function form ($instance) { 30 if ( isset( $instance[ 'title' ] ) ) { 31 $title = $instance[ 'title' ]; 32 } 33 else { 34 $title = __( 'New title', 'text_domain' ); 35 } 36 $limit = $instance['limit']; 37 $thumbnail_width = $instance['thumbnail_width']; 38 $thumbnail_height = $instance['thumbnail_height']; 39 $thumbnail_options = array('None' => 'none', 'Left' => 'left', 'Right' => 'right', 'Above' => 'above', 'Below' => 'below'); 40 ?> 41 <p> 42 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 43 <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 ); ?>" /> 44 </p> 45 <p> 46 <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Show Thumbnail:' )?></label> 47 <select name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"> 48 <?php foreach( $thumbnail_options as $description => $option ) { ?> 49 <option value="<?php echo $option ?>" <?php echo ( $instance['show_thumbnail'] == $option ? ' selected="selected"' : '' ) ?> > 50 <?php echo $description ?> 51 </option> 52 <?php } ?> 53 </select> 54 </p> 55 <p> 56 <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Category:' )?></label> 57 <select name="<?php echo $this->get_field_name( 'category' ); ?>" id="<?php echo $this->get_field_id( 'category' ); ?>"> 58 <option value=""><?php echo esc_attr( __('All Categories') ); ?></option> 59 <?php 60 $cat_args = array( 61 'orderby' => 'term_group', 62 'hide_empty' => true 63 ); 64 $categories = get_categories( $cat_args ); 65 foreach( $categories as $category ) { 66 $option = '<option value="' . $category->cat_ID . '"' . ( $instance['category'] == $category->cat_ID ? ' selected="selected"' : '' ) . '>'; 67 if( $category->parent ) 68 $option .= ' - '; 69 $option .= $category->cat_name; 70 $option .= '</option>'; 71 echo $option; 72 } 73 ?> 74 </select> 75 </p> 76 <p> 77 <label for="<?php echo $this->get_field_id( 'thumbnail_width' ); ?>"><?php _e( 'Thumbnail Width:' ); ?></label> 78 <input class="widefat" id="<?php echo $this->get_field_id( 'thumbnail_width' ); ?>" name="<?php echo $this->get_field_name( 'thumbnail_width' ); ?>" type="text" value="<?php echo esc_attr( $thumbnail_width ); ?>" /> 79 </p> 80 <p> 81 <label for="<?php echo $this->get_field_id( 'thumbnail_height' ); ?>"><?php _e( 'Thumbnail Height:' ); ?></label> 82 <input class="widefat" id="<?php echo $this->get_field_id( 'thumbnail_height' ); ?>" name="<?php echo $this->get_field_name( 'thumbnail_height' ); ?>" type="text" value="<?php echo esc_attr( $thumbnail_height ); ?>" /> 83 </p> 84 <p> 85 <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Limit:' ); ?></label> 86 <input class="widefat" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" /> 87 </p> 88 <?php 28 89 } 29 90 30 91 function update ($new_instance, $old_instance) { 31 } 32 33 function widget ($args,$instance) { 92 $instance = array(); 93 $instance['title'] = strip_tags( $new_instance['title'] ); 94 $instance['show_thumbnail'] = strip_tags( $new_instance['show_thumbnail'] ); 95 $instance['thumbnail_width'] = strip_tags( $new_instance['thumbnail_width'] ); 96 $instance['thumbnail_height'] = strip_tags( $new_instance['thumbnail_height'] ); 97 $instance['category'] = $new_instance['category']; 98 $instance['limit'] = strip_tags( $new_instance['limit'] ); 99 return $instance; 100 } 101 102 function widget ( $args, $instance ) { 34 103 extract($args); 35 104 36 $title = "Featured Posts"; 37 38 $post_args = array( 105 if (count($instance) > 0) { 106 extract( $instance ); 107 } 108 109 if (function_exists('add_image_size')) { 110 if (is_null($thumbnail_width)) { 111 $thumbnail_width = 0; 112 } 113 if (is_null($thumbnail_height)) { 114 $thumbnail_height = 0; 115 } 116 add_image_size('featured-posts-widget-thumbnail', $instance['thumbnail_width'], $instance['thumbnail_height'], true); 117 } 118 119 if (is_null($show_thumbnail)) { 120 $show_thumbnail = 'none'; 121 } 122 123 if( ! $title ) 124 $title = "Featured Posts"; 125 126 $query_args = array( 39 127 'meta_query' => array( 40 128 array( … … 42 130 'value' => 'true', 43 131 ) 44 ) 132 ), 133 'posts_per_page'=> -1, 134 'ignore_sticky_posts' => true 45 135 ); 46 47 $posts = get_posts($post_args); 48 49 if ( count($posts) > 0 ) { 50 $out = '<ul>'; 51 foreach($posts as $post) { 52 $out .= '<li><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></li>'; 53 } 136 if( $limit ) 137 $query_args['posts_per_page'] = intval( $limit ); 138 if( $category ) { 139 $query_args['tax_query'] = array( 140 array( 141 'taxonomy' => 'category', 142 'field' => 'id', 143 'terms' => intval( $category ), 144 'include_children' => false 145 ) 146 ); 147 } 148 149 $query = new WP_Query( $query_args ); 150 if( $query->post_count ) { 151 $out = '<ul class="featured-posts-widget-thumbnail-' . $instance['show_thumbnail'] . '">'; 152 while( $query->have_posts() ) { 153 $query->the_post(); 154 $out .= '<li>'; 155 if( ('above' == $show_thumbnail || 'left' == $show_thumbnail || 'right' == $show_thumbnail) && has_post_thumbnail( get_the_ID() ) ) { 156 $out .= '<a href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), "featured-posts-widget-thumbnail" ) . '</a>'; 157 } 158 if ('above' == $show_thumbnail) { 159 $out .= '<br />'; 160 } 161 $out .= '<a href="' . get_permalink() . '">' . get_the_title() . '</a>'; 162 if ('below' == $show_thumbnail) { 163 $out .= '<br />'; 164 } 165 if( ('below' == $show_thumbnail) && has_post_thumbnail( get_the_ID() ) ) { 166 $out .= '<a href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), "featured-posts-widget-thumbnail" ) . '</a>'; 167 } 168 $out .= '</li>'; 169 } 54 170 $out .= '</ul>'; 55 171 56 172 echo $before_widget; 57 echo $before_title .$title.$after_title;173 echo $before_title . $title . $after_title; 58 174 echo $out; 59 175 echo $after_widget; … … 100 216 } 101 217 218 function featured_posts_widget_scripts() { 219 wp_register_style( 'featured-posts-widget-stylesheet', plugins_url('css/featured-posts-widget.css', __FILE__), array(), '1.0' ); 220 wp_enqueue_style( 'featured-posts-widget-stylesheet' ); 221 } 222 223 add_action( 'wp_enqueue_scripts', 'featured_posts_widget_scripts' ); 224 102 225 function featured_posts_widget_load_widgets() { 103 226 register_widget('featured_posts_widget'); … … 105 228 106 229 add_action('widgets_init', 'featured_posts_widget_load_widgets'); 230 -
featured-posts-widget/trunk/readme.txt
r573986 r816887 1 1 === Plugin Name === 2 2 Contributors: tomsinger 3 Tags: featured, posts 3 Tags: featured, posts,featured posts, featured posts widget 4 4 Requires at least: 3.4.1 5 Tested up to: 3. 4.16 Stable tag: 0.15 Tested up to: 3.7.1 6 Stable tag: 1.0 7 7 License: MIT 8 8 License URI: http://www.opensource.org/licenses/mit-license.php 9 9 10 A quick and dirtyWordpress plugin to create a Featured Posts widget10 A Wordpress plugin to create a Featured Posts widget 11 11 12 12 == Description == 13 13 14 A quick and dirty Wordpress plugin to create a Featured Posts widget 14 A Wordpress plugin to create a Featured Posts widget 15 16 Features: 17 * Customisable title 18 * Select categories to choose posts from 19 * Customisable thumbnails (none, above, below, left, right) 20 * Customisable thumbnail sizes 21 22 === Thanks === 23 24 Initial image code, customisations and WP_Query refactor from https://twitter.com/_ericholmes to help create a real 1.0 version 25 26 == Changelog == 27 28 = 1.0 = 29 * Customisable title 30 * Select categories to choose posts from 31 * Customisable thumbnails (none, above, below, left, right) 32 * Customisable thumbnail sizes 33 * Better use of WP_Query
Note: See TracChangeset
for help on using the changeset viewer.