Plugin Directory

Changeset 152347


Ignore:
Timestamp:
09/05/2009 09:46:43 PM (16 years ago)
Author:
microkid
Message:

Adding version 2.4

Location:
microkids-related-posts
Files:
12 added
6 edited
9 copied

Legend:

Unmodified
Added
Removed
  • microkids-related-posts/trunk/microkids-related-posts.php

    r91181 r152347  
    33Plugin Name: Microkid's Related Posts
    44Plugin URI: http://www.microkid.net/wordpress/related-posts/
    5 Description: Manually add related posts
     5Description: Display a set of manually selected related items with your posts
    66Author: Microkid
    7 Version: 2.3
     7Version: 2.4
    88Author URI: http://www.microkid.net/
    99
     
    7979   
    8080    }
     81
    8182    function MRP_inner_custom_box() {
    8283
     
    9091        if( $post_ID ) {
    9192       
    92             if( $related_posts = MRP_get_related_posts( $post_ID ) ) {
    93            
    94                 foreach( $related_posts as $related_post_id => $related_post_title ) {
    95                
    96                     echo '<li id="related-post-'.$related_post_id.'"><span>'.$related_post_title.'</span><span><a class="MRP_deletebtn" onclick="MRP_remove_relationship(\'related-post-'.$related_post_id.'\')">X</a></span>';
    97                     echo '<input type="hidden" name="MRP_related_posts[]" value="'.$related_post_id.'" /></li>';
     93            if( $related_posts = MRP_get_related_posts( $post_ID, 1, 0 ) ) {
     94               
     95                foreach( $related_posts as $related_post ) {
     96               
     97                    $post_title = $related_post->post_title;
     98                    if( $related_post->post_type == 'page' ) {
     99                        $post_title = "[Page] " . $post_title;
     100                    }
     101                    if( $related_post->post_status != 'publish' ) {
     102                        $post_title = $post_title . ' ('.$related_post->post_status.')';
     103                    }
     104                    echo '<li id="related-post-'.$related_post->ID.'"><span>'.$post_title.'</span><span><a class="MRP_deletebtn" onclick="MRP_remove_relationship(\'related-post-'.$related_post->ID.'\')">X</a></span>';
     105                    echo '<input type="hidden" name="MRP_related_posts[]" value="'.$related_post->ID.'" /></li>';
    98106               
    99107                }           
     
    197205        $related_posts[related_post_id] => related_post_title
    198206    */
    199     function MRP_get_related_posts( $post_id ) {
    200    
     207    function MRP_get_related_posts( $post_id, $return_object = false, $hide_unpublished = true ) {
     208
    201209        global $wpdb;
    202        
     210
    203211        $options = get_option("MRP_options");
    204        
     212
    205213        if($options['display_reciprocal']) {
    206        
     214
    207215            //
    208             // Newer, faster (and definitely more SQL like) way to fetch related postings
    209             // (Thanks Peter Raganitsch @ http://blog.oracleapex.at)
    210             //
    211             $query = "SELECT wp.ID ".
    212                       ", wp.post_title ".
    213                    "FROM ".$wpdb->prefix."post_relationships    wpr ".
    214                        ",".$wpdb->prefix."posts                     wp ".
    215                   "WHERE wpr.post1_id = $post_id ".
    216                     "AND wp.id = wpr.post2_id " .
    217                  "UNION ALL ".
    218                  "SELECT wp.ID ".
    219                       ", wp.post_title ".
    220                    "FROM ".$wpdb->prefix."post_relationships    wpr ".
    221                        ",".$wpdb->prefix."posts                     wp ".
    222                   "WHERE wpr.post2_id = $post_id ".
    223                     "AND wp.id = wpr.post1_id ";
    224       }
    225       else {
    226         $query = "SELECT wp.ID ".
    227                          ", wp.post_title ".
    228                      "FROM ".$wpdb->prefix."post_relationships  wpr ".
    229                          " JOIN ".$wpdb->prefix."posts          wp ".
    230                          "  ON wpr.post2_id = wp.ID ".
    231                      "WHERE wpr.post1_id = $post_id";
     216            // Newer, faster (and definitely more SQL like) way to fetch related postings
     217            // (Thanks Peter Raganitsch @ http://blog.oracleapex.at)
     218            //
     219            $query = "SELECT * ".
     220                "FROM ".$wpdb->prefix."post_relationships   wpr ".
     221                ",".$wpdb->prefix."posts                    wp ".
     222                "WHERE wpr.post1_id = $post_id ".
     223                "AND wp.id = wpr.post2_id ";
     224            if( $hide_unpublished ) {
     225                $query .= "AND wp.post_status = 'publish'";
     226            }
     227            $query .= "UNION ALL ".
     228                "SELECT * ".
     229                "FROM ".$wpdb->prefix."post_relationships   wpr ".
     230                ",".$wpdb->prefix."posts                    wp ".
     231                "WHERE wpr.post2_id = $post_id ".
     232                "AND wp.id = wpr.post1_id ";
     233            if( $hide_unpublished ) {
     234                $query .= "AND wp.post_status = 'publish'";
     235            }
     236        }
     237        else {
     238            $query = "SELECT * ".
     239                "FROM ".$wpdb->prefix."post_relationships   wpr ".
     240                " JOIN ".$wpdb->prefix."posts               wp ".
     241                "   ON wpr.post2_id = wp.ID ".
     242                "WHERE wpr.post1_id = $post_id";
     243            if( $hide_unpublished ) {
     244                $query .= " AND wp.post_status = 'publish'";
     245            }
    232246        }
    233247
     
    235249
    236250        if( $results ) {
    237             $related_posts = array();
    238             foreach( $results as $result ) {
    239                 $related_posts[$result->ID] = $result->post_title;
    240             }
    241             return $related_posts;
     251            if( $return_object ) {
     252                return $results;
     253            }
     254            else {
     255                $related_posts = array();
     256                foreach( $results as $result ) {
     257                    $related_posts[$result->ID] = $result->post_title;
     258                }
     259                return $related_posts;
     260            }
    242261        }
    243262        return false;
     
    300319        $options = get_option("MRP_options");
    301320       
    302         $related_posts = MRP_get_related_posts( $post_id );
     321        $related_posts = MRP_get_related_posts( $post_id, 1, 1 );
    303322               
    304323        if( $related_posts ) {
     
    309328            $output .= "<ul>\n";
    310329
    311             foreach( $related_posts as $related_post_id => $related_post_title  ) {
    312                 $output .= "<li><a href=\"".get_permalink( $related_post_id )."\" title=\"$related_post_title\">".$related_post_title."</a></li>\n";
     330            foreach( $related_posts as $related_post  ) {
     331                $output .= "<li><a href=\"".get_permalink( $related_post->ID )."\" title=\"$related_post_title\">".$related_post->post_title."</a></li>\n";
    313332            }
    314333           
     
    410429        <input type="hidden" id="MRP_submit" name="MRP_submit" value="1" />
    411430    <?php
     431    }
     432   
     433   
     434    function MRP_shortcode($atts) {
     435        global $post;
     436        if( $post->ID ) {
     437            return MRP_get_related_posts_html( $post->ID );
     438        }
    412439    }
    413440   
     
    535562    add_filter('the_content', 'MRP_auto_related_posts');
    536563   
     564    add_shortcode('related-posts', 'MRP_shortcode');
     565   
     566   
    537567
    538568?>
  • microkids-related-posts/trunk/mrp-search.php

    r91181 r152347  
    3838    }
    3939   
    40     $query = "SELECT ID, post_title, post_type FROM $wpdb->posts WHERE $where AND ( post_type = 'post' OR post_type = 'page' ) AND post_status = 'publish' ";
     40    $query = "SELECT ID, post_title, post_type, post_status FROM $wpdb->posts WHERE $where AND ( post_type = 'post' OR post_type = 'page' ) ";
    4141    if( $_GET['mrp_id'] ) {
    4242        $this_id = (int) $_GET['mrp_id'];
     
    5858                echo "<strong>[Page]</strong> - ";
    5959            }
    60             echo $result->post_title.'</a> <a href="'.get_permalink( $result->ID ).'" title="View this post" class="MRP_view_post" target="_blank">&rsaquo;</a></li>';
     60            echo $result->post_title;
     61            if( $result->post_status != 'publish') {
     62                echo ' ('.$result->post_status.')';
     63            }
     64            echo '</a> <a href="'.get_permalink( $result->ID ).'" title="View this post" class="MRP_view_post" target="_blank">&rsaquo;</a></li>';
    6165            $n++;
    6266        }
  • microkids-related-posts/trunk/readme.txt

    r95771 r152347  
    11=== Microkid's Related Posts ===
    22Contributors: microkid
    3 Tags: related, posts, seo, content, articles, relevant
     3Tags: related, posts, seo, content, articles, relevant, similar
    44Requires at least: 2.5
    5 Tested up to: 2.7
     5Tested up to: 2.8.4
    66Stable tag: trunk
    77
     
    1818= Features =
    1919
    20 * Manually search and add related posts
    2120* Easily find posts or pages that might be related to the one you are writing with an integrated AJAX powered search utility
    2221* Easily add and remove relations with a single click. No page reloads, no pop-ups
     
    4039
    4140= Does this plugin work with Wordpress versions &lt; 2.5? =
    42 No, unfortunately it is not yet backward compatible with Wordpress version older than 2.5.
     41No, it is not yet backward compatible with Wordpress version older than 2.5.
    4342
    4443= What will be displayed if there are no related posts? =
    4544You can use a custom message, or display nothing at all (no text, no code).
    4645
    47 = Is there any way to grab the related posts in PHP, so I can display them somewhere else instead of underneath my post? =
    48 Yes, there is a set of [API functions](http://www.microkid.net/wordpress/related-posts/#API "Microkids Related Posts API functions") available to help you do this.
     46= How can I customize the way the related posts are displayed? =
     47There is a set of [API functions](http://www.microkid.net/wordpress/related-posts/#API "Microkids Related Posts API functions") available you can use in your themes.
    4948
    5049= I'm having trouble using this plugin. How can I reach you? =
     
    5857
    5958== Change Log ==
     59
     60= 2.4 =
     61* You can now add drafts and planned posts as related posts, without them appearing on your site before they are properly published.
     62* Added shortcode support - you can now place the [related-posts] shortcode within the content of your post to display the related posts anywhere you want.
     63* (For advanced users) Added a parameter to the MRP_get_related_posts function to optionally get the related posts in an object, so you can easily use it in other plugins or your own custom way of displaying the list of related posts. For documentation on this, see [the API section](http://www.microkid.net/wordpress/related-posts/#API "Microkids Related Posts API functions").
    6064
    6165= 2.3 =
Note: See TracChangeset for help on using the changeset viewer.