• Resolved khermberg

    (@khermberg)


    How can I make the excerpt be text rather than a link and add a read more link?

    When I ask for the full content, it behaves as expected. However, when I ask for an excerpt, the whole excerpt becomes a link to the post, rather than merely an excerpt of the post.

    What I need is for the title to be a link, the excerpt to be standard text, and the […more] to be the link. I see that you helped someone else out with a patch for the read more link, so I trust this is possible. I am comfortable editing the files if you can point me in the right direction.

    If these can be done, this will be the perfect plugin for my situation.

    https://www.ads-software.com/plugins/onespace-lastpost/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author igrossiter

    (@igrossiter)

    Hi, sorry for the late response, you can try to change it on core/class-os-lastpost-printer.php, the trimContent function on line 161.

    change:

    if (strlen($content) > $max_char - strlen($text)){
    			$content = substr($content, 0, $max_char) . $text;
    		}

    to

    if (strlen($content) > $max_char - strlen($text)){
    			$content = substr($content, 0, $max_char);
    		}

    and

    return '<p><a href="' . get_permalink($p->ID) . '">' . $content . '</a></p>';

    to

    return '<p>'.$content.'<a href="' . get_permalink($p->ID) . '">' . $text . '</a></p>';

    UNTESTED

    Thread Starter khermberg

    (@khermberg)

    Thank you for your reply.

    I have not fully tested your suggestion, but I have made those changes and at first glance they appear to have done the trick. Thank you!

    One unexpected and unwanted result is that the ‘read more’ tag now appears even if the post is shorter than the specified excerpt length. Before the change, if the post was that short, the tag did not appear. The ideal would be for the tag to only appear if the post is longer than the excerpt, but if the choice is between the original behavior and the behavior after the fix you suggested, for my purposes, the fix is better.

    Do you think you will include that change in your next update? That (combined with the read more tag only showing when the post is longer than the excerpt length) would have the excerpts yielded by the plugin behaving in a manner that is typical of blog excerpts.

    Nice plugin. Thanks.

    Plugin Author igrossiter

    (@igrossiter)

    Nice, another quick fix would be changing:

    if (strlen($content) > $max_char - strlen($text)){
      $content = substr($content, 0, $max_char);
    }

    to

    if (strlen($content) > $max_char - strlen($text)){
      $content = substr($content, 0, $max_char);
    } else {
      $text = '';
    }

    That would check if the text is bigger, then reduce it. If not I removes de content of the $text variable. not tested!

    Yes, I can add it to the next release, although I’m not sure when its gonna be, note taken!

    Thread Starter khermberg

    (@khermberg)

    Very nice. That seems to have done the trick. Kicking myself for not thinking of the “else.”

    Thanks for your help and your quick replies.

    Plugin Author igrossiter

    (@igrossiter)

    You’re welcome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Unlink the excerpt and add a read more link?’ is closed to new replies.