Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #23369

    Hi could someone help me with the latest blog page? I need every blog article to be trimmed. Let’s say trim 300 words and after that a read more link shows up. I know I could apply the read more tag in the article but i’ve got more than 100 articles and there must be a sort of function to create what I need right?

    In the current situation all the blog posts fully shows up now instead of a part of it.

    Hope someone could help me out.

    Thanks!

    #119545

    Hi,

    Edit a post then go to the end of a certain paragraph that you want to show as an excerpt. Add this code below.

    <!--more-->

    This will strip away all of the text below and create a Read more link.

    Regards,

    Ismael

    #119546

    Hi Ismael,

    Like I said in the previous comment, I know I can do that, but since I have more than 100 articles I need a kind of function to apply this to every article. For example lets say, trim the text after 100 words.

    I a piece of code, but it trims the whole blog article instead of giving a preview with a read more link.

    Could you give me advise how to integrate this?

    Thanks

    #119547

    I used this piece of code in includes/loop-index.php

    $current_post = wp_trim_words( get_the_content(), 100);

    #119548

    Hey fernon,

    Dead on with your change to the main loop. Since 3.3 the wp_trim_words is the best way to do that instead of the old functions that filter through the content.

    Regards,

    Devin

    #119549

    Hi Devin,

    The problem is that when I implement this function in $current_post, that all the content in the site gets trimmed. Not only the blog index “preview” page. Where do I need to put this function? In loop-index.php right?

    #119550

    Hi!

    Please try to use a conditional like:

    $current_post['content'] = is_single() ? get_the_content() : wp_trim_words( get_the_content(), 100);

    Regards,

    Peter

    #119551

    Works perfectly! Thanks mate.

    #119552

    Hi!

    Great :)

    Regards,

    Peter

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Trim blog page text.’ is closed to new replies.