WordPress.org

Ready to get started?Download WordPress

Forums

Making entire excerpt clickable (6 posts)

  1. Athene Molina
    Member
    Posted 6 years ago #

    I was curious how to make the entire text clickable in the_excerpt. Is this possible? Sorta like n-tv or cnn has it. There's a linkable title and some text but rarely do they use "more" they have the entire excerpt of content clickable.

    Also, if this it not possible or just to know, how does one truncate the title to a specified number of words or characters?

  2. Athene Molina
    Member
    Posted 6 years ago #

    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_excerpt(); ?></a>... doh

    for the first part anyway, any ideas on the title truncation?

  3. Ivovic
    Member
    Posted 6 years ago #

    You could use a little php function called substr()

    <?php echo substr(the_title('','',FALSE), 0, 30); ?>

    change the 30 to however many characters you'd like.

  4. Ivovic
    Member
    Posted 6 years ago #

    you might want to make this super-pretty by doing something like this:

    <?php
      $cutoff = 30;
      $title = the_title('','',FALSE);
      if (strlen($title)>$cutoff) echo substr($title, 0, 30).'...';
      else echo $title;
    ?>

    that'll put a '...' at the end of your titles, but only if something's been cut off.

    you could also replace the dots above with the HTML entity '&#8230;'

  5. Athene Molina
    Member
    Posted 6 years ago #

    YOU ROCK!!! Thanks :-) Worked like a charm.

    I was using Joomla for a while and am so happy to be returning to WordPress... Joomla is ok for what it is, but it's in no way a writing platform!

    :-)

  6. Ivovic
    Member
    Posted 6 years ago #

    I missed a spot in the addon I posted above... too late to edit.
    it won't break anything, but this is what I intended to post:

    <?php
      $cutoff = 30;
      $title = the_title('','',FALSE);
      if (strlen($title)>$cutoff) echo substr($title, 0, $cutoff).'...';
      else echo $title;
    ?>

    Glad it works for you.

Topic Closed

This topic has been closed to new replies.

About this Topic