WordPress.org

Ready to get started?Download WordPress

Forums

show read more only when content is long.. (6 posts)

  1. nyckidd
    Member
    Posted 1 year ago #

    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

  2. dwnmedia sarl
    Member
    Posted 1 year ago #

    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

  3. nyckidd
    Member
    Posted 1 year ago #

    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;
    }
  4. dwnmedia sarl
    Member
    Posted 1 year ago #

    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()
  5. nyckidd
    Member
    Posted 1 year ago #

    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..

  6. c.bavota
    Member
    Posted 1 year ago #

    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' );

Topic Closed

This topic has been closed to new replies.

About this Topic