Changeset 1013021
- Timestamp:
- 10/23/2014 06:52:22 PM (11 years ago)
- Location:
- simply-related-posts/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
simply-related-posts.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simply-related-posts/trunk/readme.txt
r707086 r1013021 4 4 Tags: related posts, taxonomy, widget 5 5 Requires at least: 3.0.1 6 Tested up to: 3.57 Stable tag: 1. 26 Tested up to: 4.0 7 Stable tag: 1.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 A widget that simply gives you related posts by taxonomy. Four settings to 11 A widget that simply gives you related posts by taxonomy. Four settings to 12 12 customize the widget: title, taxonomy, related posts count, excludet terms 13 13 14 14 == Description == 15 15 16 A widget that simply gives you related posts by taxonomy. It provides four 17 settings to customize every widget and there are no global settings to worry 18 about. 16 A widget that simply gives you related posts by taxonomy. It provides four 17 settings to customize every widget and there are no global settings to worry 18 about. 19 19 20 20 **Widget settings** … … 45 45 46 46 Q. How to add thumbnail images to the related posts list 47 A. You can add the 'simply_related_posts_title' filter, like 47 A. You can add the 'simply_related_posts_title' filter, like 48 48 `add_filter( 'simply_related_posts_title', 'my_related_posts', 10, 2);` 49 49 The first argument is a post-object for the related post, the second argument 50 is the widget instance. 50 is the widget instance. 51 51 52 52 -
simply-related-posts/trunk/simply-related-posts.php
r707086 r1013021 3 3 Plugin Name: Simply Related Posts 4 4 Plugin URI: http://www.danielauener.com/simply-related-posts/ 5 Description: A widget that simply gives you related posts by taxonomy. 6 Version: 1. 25 Description: A widget that simply gives you related posts by taxonomy. 6 Version: 1.3 7 7 Author: @danielauener 8 8 Author URI: http://www.danielauener.com 9 9 */ 10 class SimplyRelatedPosts extends WP_Widget { 10 class SimplyRelatedPosts extends WP_Widget { 11 11 12 12 … … 15 15 $widget_ops = array( 16 16 'classname' => 'SimplyRelatedPosts', 17 'description' => __( 'Shows up when is_single() is true and contains 17 'description' => __( 'Shows up when is_single() is true and contains 18 18 posts with one or more matching terms.' , 'simply-related-posts') 19 19 ); 20 20 $this->WP_Widget( 'SimplyRelatedPosts', __( 'Simply Related Posts' , 'simply-related-posts'), $widget_ops ); 21 21 22 add_action( ' plugins_loaded', array( &$this , 'load_text_domain' ) );22 add_action( 'init', array( $this , 'load_text_domain' ) ); 23 23 } 24 24 25 26 function load_text_domain() {27 25 28 $plugin_dir = "simply-related-posts/languages/"; 29 load_plugin_textdomain( 'simply-related-posts', false, $plugin_dir ); 30 31 } 26 function load_text_domain() { 27 load_plugin_textdomain( 'simply-related-posts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 28 } 32 29 33 34 30 function form( $instance ) { 35 31 36 32 $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Related Posts' , 'simply-related-posts'), 'exclude' => '', 'taxonomy' => 'post_tag', 'post_type' => 'post', 'related_count' => '5' ) ); 37 33 $title = $instance['title']; 38 $post_type = $instance['post_type']; 39 $taxonomy = $instance['taxonomy']; 34 $post_type = $instance['post_type']; 35 $taxonomy = $instance['taxonomy']; 40 36 $exclude = $instance['exclude']; 41 37 $related_count = $instance['related_count']; ?> … … 48 44 <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"> 49 45 <?php _e( 'Related by taxonomy' , 'simply-related-posts'); ?>: <select class="widefat" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>"><?php 50 $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'objects' ); 46 $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'objects' ); 51 47 foreach ( $taxonomies as $slug => $tax ): ?> 52 48 <option value="<?php echo $slug; ?>" <?php echo ( $slug == $taxonomy ) ? 'selected="selected"' : ''; ?>><?php echo $tax->labels->name; ?></option><?php 53 49 endforeach; ?> 54 50 </select> 55 </label> 51 </label> 56 52 </p> 57 53 <p> 58 54 <label for="<?php echo $this->get_field_id( 'post_type' ); ?>"> 59 55 <?php _e( 'Related post-type' , 'simply-related-posts'); ?>: <select class="widefat" id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name( 'post_type' ); ?>"><?php 60 $post_types = get_post_types( array( 'show_ui' => true, 'public' => true ), 'objects', 'and' ); 56 $post_types = get_post_types( array( 'show_ui' => true, 'public' => true ), 'objects', 'and' ); 61 57 foreach ( $post_types as $slug => $pt ): ?> 62 58 <option value="<?php echo $slug; ?>" <?php echo ( $slug == $post_type ) ? 'selected="selected"' : ''; ?>><?php echo $pt->labels->name; ?></option><?php 63 59 endforeach; ?> 64 60 </select> 65 </label> 66 </p> 61 </label> 62 </p> 67 63 <p> 68 64 <label for="<?php echo $this->get_field_id( 'related_count' ); ?>"> 69 65 <?php _e( 'How many posts to show' , 'simply-related-posts'); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'related_count' ); ?>" name="<?php echo $this->get_field_name( 'related_count' ); ?>" type="text" value="<?php echo attribute_escape( $related_count ); ?>" /> 70 </label> 66 </label> 71 67 </p> 72 68 <p> 73 69 <label for="<?php echo $this->get_field_id( 'exclude' ); ?>"> 74 70 <?php _e( 'Term ids to exclude (e.g 5,4,2)' , 'simply-related-posts'); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'exclude' ); ?>" name="<?php echo $this->get_field_name( 'exclude' ); ?>" type="text" value="<?php echo attribute_escape( $exclude ); ?>" /> 75 </label> 71 </label> 76 72 </p><?php 77 73 78 74 } 79 75 80 76 81 77 function update( $new_instance, $old_instance ) { … … 90 86 91 87 } 92 88 93 89 94 90 function widget( $args, $instance ) { … … 103 99 $taxonomy = ( $instance['taxonomy'] == "" ) ? 'post_tag' : $instance['taxonomy']; 104 100 $terms = wp_get_post_terms( get_the_ID(), $taxonomy, array( 'fields' => 'ids' )); 105 101 106 102 $exclude = ( empty( $instance['exclude'] ) ) ? array() : explode( ',', $instance['exclude'] ); 107 103 if ( count( ( $terms = array_diff( $terms, $exclude ) ) ) == 0 ) 108 104 return; 109 105 110 106 $related_posts = get_posts( array( 111 107 'tax_query' => array( … … 115 111 'terms' => $terms, 116 112 'operator' => 'IN' 117 ) 113 ) 118 114 ), 119 115 'post_type' => $post_type, … … 143 139 144 140 } 145 141 146 142 } 147 143
Note: See TracChangeset
for help on using the changeset viewer.