Support » Fixing WordPress » show read more only when content is long..

  • hey guys, i got the below code showing the read more with a max of 90 words, see below..

    <?php content('90'); ?> <a href="<?php the_permalink(); ?>">Read More</a>

    now i need to modify it so that if the content is only 80 words then the read more does not show, right now the content with 80 words has the read more…

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Where have you found this function called “content()” is it your own func?

    I know the get_the_content(), the_content()

    May we have some details about this function?

    You would need probably to put a condition but without extra details it is a little bit hard to help you

    Here is the function…

    function content($num) {
    $theContent = get_the_content();
    $output = preg_replace('/<img[^>]+./','', $theContent);
    $output = preg_replace( '/<blockquote>.*<\/blockquote>/', '', $output );
    $output = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $output );
    $limit = $num+1;
    $content = explode(' ', $output, $limit);
    array_pop($content);
    $content = implode(" ",$content)."...";
    echo $content;
    }

    Are you OK with PHP code?
    You probably will need to modify this function and to have a condition checking

    • if $content has more than 80 words -> then display the_permalink()

    am not a php guy, just got the function from this forum before i realized that i need to have the read mmore not show…can you just do an example and i can run with it and play around with it..

    You can remove that anchor tag from the first code snippet and then modify the function so that you include your read more within the get_the_content() function like so:

    $theContent = get_the_content( 'Read more' );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘show read more only when content is long..’ is closed to new replies.