How to automatically insert a list of related articles between the content

There are many ways to show related articles, such as code generated related posts with tumbnails. Here, I will show you another way. It is automatically insert a list of related articles between the content

Please follow me:



// Code count the number of lines in text
function count_paragraph( $insertion$paragraph_id$content ) {
        $closing_p '</p>';
        $paragraphs explode$closing_p$content );
        foreach ($paragraphs as $index => $paragraph) {
                if ( trim( $paragraph ) ) {
                        $paragraphs[$index] .= $closing_p;
                }
                if $paragraph_id == $index + 1 ) {
                        $paragraphs[$index] .= $insertion;
                }
        }
        return implode( ''$paragraphs );
}
//Insert a list of related articles between the content
add_filter( 'the_content''prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
        $related_posts= do_shortcode('[related_posts_by_tax title=""]');
        if ( is_single() ) {
                return count_paragraph( $related_posts, 1, $content );
        }
        return $content;
}

The results are as follows:


Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

3 comments

  1. Life is fun when you always let go and then get back feeling happy
    hotmail.com entrar

    ReplyDelete
  2. I am so grateful to find your particular post. I have bookmarked this website and I will keep visiting you for further such interesting posts.
    criar uma conta hotmail

    ReplyDelete
  3. More importantly, these numbers would also put Gmail in front of the Hotmail.com , run by Microsoft, making Gmail the email service most used in the world. In July 2011, Microsoft said that Hotmail had 360 million users. The company has not offered an update since.

    ReplyDelete

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
Posts RSSComments RSSBack to top
© 2011 Sharing the best tips for you and for me ∙ Designed by BlogThietKe
Released under Creative Commons 3.0 CC BY-NC 3.0