[Plugin: Yet Another Related Posts Plugin] YARPP Feature Suggestion: Display Related Posts in-line
-
I wanted to display the related posts/pages in-line with the post. (So that the related posts display after the first paragraph).
I have managed to hack something together for my purposes, but it would be really nice if this feature could be added as an option in version 2.
You can seen an example of the rendering at:
https://www.momentummt.ca/MassageTherapy/2007/10/01/plantar-fasciitis-a-real-pain-in-the-foot/To do this:
1) I added a new filter in yarpp.php
add_filter('the_content', 'yarpp_mmt_related');
2) I commented out the following line in yarpp.php
add_filter('the_content','yarpp_default');
3) In magic.php – I changed line 30 as follows:
$string = str_repeat($post->post_title, $w['title'].' ').str_repeat(str_replace('-', ' ', $post->post_name).' ', $w['name']).str_repeat(strip_tags(apply_filters_without('the_content',$post->post_content,'yarpp_mmt_related')), $w['content'].' ');//mitcho: strip_tags
4) Finally I wrote the following function. Obviously with the hardcoding currently in place it is specific to my needs.
function yarpp_mmt_related($content) { global $wpdb, $post, $user_level; if (is_single()) { // get related posts $related_mmt = yarpp_related(array('post'),array(),false); // find the the first close paragraph tag $pos = strpos($content, '</p>'); // insert the related entries into the article $content = substr_replace($content, '</p><div id=\'relposts\'><h3>Related Articles</h3>'.$related_mmt.'</div>', $pos, 4); // send it back return $content; } else { return $content; } }
Thanks for considering this,
Bruce.
- The topic ‘[Plugin: Yet Another Related Posts Plugin] YARPP Feature Suggestion: Display Related Posts in-line’ is closed to new replies.