StartAdministrationRelated Posts extended

Related Posts extended

-

 2011-10-20 02:42:08

http://wordpress.org/extend/plugins/efficient-related-posts/

 

 

Dear friend, great plugin relatedPost

 

I made the addition and extension of thumbs and post excerpt, not absolutely waterproof but good enough for most. Couldn’t log into your website for some “re-capture” reason, so please post it yourself on your forum, might help others.

 to publish it it needs the optional paras set, as is now its default, is 10min extra work.

and the replacement for the default thumb in efficient related posts

 

tx for the great plugin!

 

 

 

 

Replace following function in file efficient-related-posts.php

 

[fancy_code_box]

 

                /**

                 * @param [optional]$args Array of arguments containing any of the following:

                 *            [num_to_display]           – Number of Posts to display

                 *            [no_rp_text]                     – Text to display if there are no related posts

                 *            [title]                                                   – Title for related posts list, empty for none

                 */

                public function getRelatedPosts( $args = array() ) {

                               global $post;

                               $output = ”;

 

                               $settings = wp_parse_args($args, $this->_settings[‘erp’]);

 

                               $relatedPosts = get_post_meta($post->ID, ‘_efficient_related_posts’, true);

 

                               if ( empty($relatedPosts) || $settings[‘num_to_display’] == 0 ){

                                               /**

                                                * @todo The before and after setting should apply to this too

                                                */

                                               $output .= “<li>{$settings[‘no_rp_text’]}</li>”;

                               } else {

                                               $relatedPosts = array_slice($relatedPosts, 0, $settings[‘num_to_display’]);

                                               foreach ( $relatedPosts as $p ) {

                                                               /**

                                                                * Handle IDs for backwards compat

                                                                */

                                                               if ( ctype_digit($p) ) {

                                                                              $related_post = get_post($p);

                                                                              $p = array(

                                                                                              ‘ID’                                         => $related_post->ID,

                                                                                              ‘post_title’          => $related_post->post_title,

                                                                                              ‘permalink’                         => get_permalink($related_post->ID)

                                                                              );

                                                               }

                                                               $link = “<a href='{$p[‘permalink’]}’ title='” . esc_attr(wptexturize($p[‘post_title’])).”‘>”.wptexturize($p[‘post_title’]).'</a>’;

                           

                                                              

                                                               $backup = $post;

                            $pp = get_post($p[‘ID’]);

                            $thumb = get_the_post_thumbnail($pp->ID, ‘thumbnail’, array(‘class’ => ‘RelPosts’));   

               

                if (empty($thumb)) {

                      $thumb = “<img width=’150′ height=’133′ src=’https://ganzemedizin.at/wp-content/uploads/Retzek-forscht-150×133.jpg’ class=’RelPosts wp-post-image’ alt=’Retzek forscht’ title=’Retzek verschweinzt Naechte und Wochenenden um die Wahrheit auszugraben’>”;

                      }         

               

               

               

                                                               If ($pp->post_excerpt != ”){

                                                               // get the users excerpt

                                                                              $excerpt = $post->post_excerpt;

                                                                              }

                                                               Else {

                                                               // Create the excerpt

                                                               $excerpt = $pp->post_content;

                                                               $excerpt = strip_shortcodes( $excerpt );

                                                               $excerpt = apply_filters(‘the_content’, $excerpt);

                                                               $excerpt = str_replace(‘]]>’, ‘]]&gt;’, $excerpt);

                                                               $excerpt = strip_tags($excerpt);

                                                               $excerpt_length = apply_filters(‘excerpt_length’, 55);

                                                               $excerpt_more = apply_filters(‘excerpt_more’, ‘[…]’);

                                                               $words = explode(‘ ‘, $excerpt, $excerpt_length + 1);

                                                               If ( Count($words) > $excerpt_length ){

                                                                 Array_Pop($words);

                                                                 Array_Push($words, $excerpt_more);

                                                                 $excerpt = Implode(‘ ‘, $words);

                                                               }

                                                 }

                                                

                                                 // Run filters – there is a bug if you try to run an empty excerpt through the filter

                                                 If ($excerpt != ”) $excerpt = apply_filters(‘get_the_excerpt’, $excerpt);

 

                          $post = $backup;                                   

                                                              

                                                                /* @todo Make a before and after setting for this

                                                                */

                                                               $output .= “$thumb <li>{$link}<div><p class=’RelPosts’>$excerpt</p></div></li><div style=’clear:both;’>&nbsp</div>”;

                                               }

                               }

 

                               /**

                                * @todo Make a before and after setting for this

                                */

                               $output = “<ul class=’related_post’>{$output}</ul>”;

 

                               if ( !empty($settings[‘title’]) ) {

                                               $output = “<div class=’RelPostHeli’><h3 class=’related_post_title’>{$settings[‘title’]}</h3>{$output}</div>”;

                               }

 

                               return $output;

                }

 

 

 

 

 

 

 

CSS

div.RelPostHeli {margin:-20px;padding:20px;background-color:snow;}

ul.related_post li p.RelPosts {font-size:11px;color:grey;margin:5px 0 10px 10px;}

ul.related_post li div p.RelPosts img.RelPosts, ul.related_post img.RelPosts { 

    background: none repeat scroll 0 0 lavender;

    float: left;

    height: 120px;

    left: -20px;

    margin: 2px 42px 4px -24px;

    padding: 8px;

    top: -10px;

    width: 120px;

}

 

 

 [/fancy_code_box]

 

 

Vorheriger Artikel
Nächster Artikel

Kommentieren Sie den Artikel

Bitte geben Sie Ihren Kommentar ein!
Bitte geben Sie hier Ihren Namen ein

×