Skip to content
Browse files

Initial

  • Loading branch information...
1 parent 15f6b2e commit b58267925eb83a720a6fbcb77f1fc78ded0cce6b @danielauener committed
Showing with 245 additions and 1 deletion.
  1. +3 −1 README.md
  2. +61 −0 languages/simply-related-posts.pot
  3. +48 −0 readme.txt
  4. BIN screenshot-1.png
  5. +133 −0 simply-related-posts.php
View
4 README.md
@@ -1,4 +1,6 @@
wp-simply-related-posts
=======================
-A WordPress widget that simply gives you related posts by taxonomy.
+A WordPress widget that simply gives you related posts by taxonomy.
+
+Get a description on how to use it on [danielauener.com/simply-related-posts/](http://www.danielauener.com/simply-related-posts
View
61 languages/simply-related-posts.pot
@@ -0,0 +1,61 @@
+# Copyright (C) 2013 Simply Related Posts
+# This file is distributed under the same license as the Simply Related Posts package.
+msgid ""
+msgstr ""
+"Project-Id-Version: Simply Related Posts 1.0\n"
+"Report-Msgid-Bugs-To: http://wordpress.org/tag/simply-related-posts\n"
+"POT-Creation-Date: 2013-01-14 21:39:11+00:00\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"PO-Revision-Date: 2013-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+
+#: simply-related-posts.php:17
+msgid ""
+"Shows up when is_single() is true and contains \n"
+" posts with one or more matching terms."
+msgstr ""
+
+#. #-#-#-#-# simply-related-posts.pot (Simply Related Posts 1.0) #-#-#-#-#
+#. Plugin Name of the plugin/theme
+#: simply-related-posts.php:20
+msgid "Simply Related Posts"
+msgstr ""
+
+#: simply-related-posts.php:36
+msgid "Related Posts"
+msgstr ""
+
+#: simply-related-posts.php:43
+msgid "Title"
+msgstr ""
+
+#: simply-related-posts.php:48
+msgid "Related by taxonomy"
+msgstr ""
+
+#: simply-related-posts.php:58
+msgid "How many posts to show"
+msgstr ""
+
+#: simply-related-posts.php:63
+msgid "Term ids to exclude (e.g 5,4,2)"
+msgstr ""
+
+#. Plugin URI of the plugin/theme
+msgid "http://www.danielauener.com/simply-related-posts/"
+msgstr ""
+
+#. Description of the plugin/theme
+msgid "A widget that simply gives you related posts by taxonomy."
+msgstr ""
+
+#. Author of the plugin/theme
+msgid "@danielauener"
+msgstr ""
+
+#. Author URI of the plugin/theme
+msgid "http://www.danielauener.com"
+msgstr ""
View
48 readme.txt
@@ -0,0 +1,48 @@
+=== Plugin Name ===
+Contributors: danielauener
+Donate link: http://www.danielauener.com/
+Tags: related posts, taxonomy, widget
+Requires at least: 3.0.1
+Tested up to: 3.5
+Stable tag: trunk
+License: GPLv2 or later
+License URI: http://www.gnu.org/licenses/gpl-2.0.html
+
+A widget that simply gives you related posts by taxonomy. Four settings to
+customize the widget: title, taxonomy, related posts count, excludet terms
+
+== Description ==
+
+A widget that simply gives you related posts by taxonomy. It provides four
+settings to customize every widget and there are no global settings to worry
+about.
+
+**Widget settings**
+
+1. The title of the widget (default: Related Posts)
+2. The taxonomy by which terms the posts are related (default: Tags)
+3. How many related posts to show (default 5)
+4. excludet terms
+
+The widget is visible only when `is_single()` is true, it doesn't shows up on
+archives, search templates etc.
+
+== Installation ==
+
+1. Upload the `simply-related-posts` folder to the `/wp-content/plugins/` directory
+2. Activate the plugin through the 'Plugins' menu in WordPress
+3. Go to the 'Apearance/Widgets' area, add the 'Simply Related Posts' widget to
+a widget area.
+4. Make your settings
+5. done
+
+== Frequently Asked Questions ==
+
+== Screenshots ==
+
+1. Widget settings
+
+== Changelog ==
+
+= 1.0 =
+* Version 1.0 done
View
BIN screenshot-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
133 simply-related-posts.php
@@ -0,0 +1,133 @@
+<?php
+ /*
+ Plugin Name: Simply Related Posts
+ Plugin URI: http://www.danielauener.com/simply-related-posts/
+ Description: A widget that simply gives you related posts by taxonomy.
+ Version: 1.0
+ Author: @danielauener
+ Author URI: http://www.danielauener.com
+ */
+ class SimplyRelatedPosts extends WP_Widget {
+
+
+ function SimplyRelatedPosts() {
+
+ $widget_ops = array(
+ 'classname' => 'SimplyRelatedPosts',
+ 'description' => __( 'Shows up when is_single() is true and contains
+ posts with one or more matching terms.' , 'simply-related-posts')
+ );
+ $this->WP_Widget( 'SimplyRelatedPosts', __( 'Simply Related Posts' , 'simply-related-posts'), $widget_ops );
+
+ add_action( 'plugins_loaded', array( &$this , 'load_text_domain' ) );
+ }
+
+
+ function load_text_domain() {
+
+ $plugin_dir = "simply-related-posts/languages/";
+ load_plugin_textdomain( 'simply-related-posts', false, $plugin_dir );
+
+ }
+
+
+ function form( $instance ) {
+
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Related Posts' , 'simply-related-posts'), 'exclude' => '', 'taxonomy' => 'post_tag', 'related_count' => '5' ) );
+ $title = $instance['title'];
+ $taxonomy = $instance['taxonomy'];
+ $exclude = $instance['exclude'];
+ $related_count = $instance['related_count']; ?>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>">
+ <?php _e( 'Title' , 'simply-related-posts'); ?>: <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo attribute_escape( $title ); ?>" />
+ </label>
+ </p>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>">
+ <?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
+ $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'objects' );
+ foreach ( $taxonomies as $slug => $tax ): ?>
+ <option value="<?php echo $slug; ?>" <?php echo ( $slug == $taxonomy ) ? 'selected="selected"' : ''; ?>><?php echo $tax->labels->name; ?></option><?php
+ endforeach; ?>
+ </select>
+ </label>
+ </p>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'related_count' ); ?>">
+ <?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 ); ?>" />
+ </label>
+ </p>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'exclude' ); ?>">
+ <?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 ); ?>" />
+ </label>
+ </p><?php
+
+ }
+
+
+ function update( $new_instance, $old_instance ) {
+
+ $instance = $old_instance;
+ $instance['title'] = $new_instance['title'];
+ $instance['related_count'] = $new_instance['related_count'];
+ $instance['exclude'] = $new_instance['exclude'];
+ $instance['taxonomy'] = $new_instance['taxonomy'];
+ return $instance;
+
+ }
+
+
+ function widget( $args, $instance ) {
+
+ if ( !is_single() )
+ return;
+
+ extract( $args, EXTR_SKIP );
+
+ $taxonomy = ( $instance['taxonomy'] == "" ) ? 'post_tag' : $instance['taxonomy'];
+ $terms = wp_get_post_terms( get_the_ID(), $taxonomy, array( 'fields' => 'ids' ));
+
+ $exclude = ( empty( $instance['exclude'] ) ) ? array() : explode( ',', $instance['exclude'] );
+ if ( count( ( $terms = array_diff( $terms, $exclude ) ) ) == 0 )
+ return;
+
+ $related_posts = get_posts( array(
+ 'tax_query' => array(
+ array(
+ 'taxonomy' => $taxonomy,
+ 'field' => 'id',
+ 'terms' => $terms,
+ 'operator' => 'IN'
+ )
+ ),
+ 'posts_per_page' => $related_count,
+ 'exclude' => get_the_ID()
+ ) );
+
+ if ( count( $related_posts ) == 0 )
+ return;
+
+ echo $before_widget;
+
+ $title = empty( $instance['title'] ) ? ' ' : apply_filters( 'widget_title', $instance['title'] );
+ if ( !empty( $title ) )
+ echo $before_title . $title . $after_title; ?>
+ <ul><?php
+ foreach ( $related_posts as $related_post ) : ?>
+ <li>
+ <a class="related-post" href="<?php echo get_permalink( $related_post->ID ); ?>">
+ <?php echo $related_post->post_title; ?>
+ </a>
+ </li><?php
+ endforeach; ?>
+ </ul><?php
+
+ echo $after_widget;
+
+ }
+
+ }
+
+ add_action( 'widgets_init', create_function( '', 'return register_widget( "SimplyRelatedPosts" );' ) );

0 comments on commit b582679

Please sign in to comment.
Something went wrong with that request. Please try again.