WordPress.org

Ready to get started?Download WordPress

Forums

if more than 1 paragraph show 'Read more' (1 post)

  1. Reakon
    Member
    Posted 1 year ago #

    Dear WordPress goeroes,

    Lately I have been busy building a new blog and found this pretty code I use now for my blog to show only the first paragraph as excerpt:

    if(!function_exists('get_the_content_first_paragraph')) :
    function get_the_content_first_paragraph() {
        $content = get_the_content();
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
        $content_explode = explode("</p>", $content);
    
        $c = 0; $p = count($content_explode); $return_data = "";
        while($c < $p) {
            $test = strip_tags($content_explode[$c]);
            if($test != '') {
                $return_data = $return_data . $content_explode[$c] . "</p>\n";
                break;
            } else {
                $return_data = $return_data . $content_explode[$c] . "</p>\n";
            } $c++;
        }
        return $return_data;
    }
    endif;

    &

    <?php
        if($pos = strpos($post->post_content, '<!--more-->')) :
            the_content(__(''));
        else :
            echo get_the_content_first_paragraph();
        endif;
    ?>
    
    Source: http://jshamsul.com/2012/02/08/wordpress-get-first-paragraph-from-post/

    Anyway, now I would like to show the 'Read More' button ONLY when there is more than 1 paragraph, could someone please help with that little bit of code?

    [No bumping. If it's that urgent, consider hiring someone.]

Topic Closed

This topic has been closed to new replies.

About this Topic