WordPress.org

Ready to get started?Download WordPress

Forums

Display the_content() or the_excerpt() conditionally (4 posts)

  1. drteddy
    Member
    Posted 2 years ago #

    In my blog http://www.drteddy.gr in the front page the template displays the excerpt of the post.

    I want to display the_content() of the post depending on the number of the words of the post. I've coded a function that counts the post's words, but I couldn't implement the part I describe above.

    Could anyone give me a clue or help?

  2. Nasir Zia
    Member
    Posted 2 years ago #

    try This

    $max=40;
    if ($count> $max) {
    
    the_excerpt();
    }
    
    else {
    
    the_content();
    }
  3. drteddy
    Member
    Posted 2 years ago #

    It doesn't work....

    For some reason the if statement always returns the part of the code that included in "else" section....

    Giving some more tries...

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    I've coded a function that counts the post's words

    instead of $count use the returned value from that function (don't use echo in your function , but use return).

    possibly post the code of that function here - see forum guidelines for posting code.

Topic Closed

This topic has been closed to new replies.

About this Topic