• Right now I’m using a modified child version of the Twenty Ten theme, and in the loop-single-post.php there’s a bit of code that allows you to navigate from this post’s page to the next or previous post.

    I really like this function, but if the title for either the next or previous post is too long, it looks awful and adds space to the top of the page. Is there any way to limit the amount of characters that is shown from the string ‘%link’?

    e.g. if the actual string for %link is “Man, isn’t summer just the greatest time ever?”, and I want to shorten it such that it looks like “Man, isn’t summer just…”, how do I do that?

    I imagine I change the string to at least ‘%link…’, but how do I get the php to recognize not to print more than x amount of characters of %link?

    Any help would be greatly appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You mean read more? Use the following function

    /*
    Credit : http://bit.ly/OKhlb0
    -------Functions Trime Excerpt --------*/
    
    function get_excerpt($count){
      $permalink = get_permalink($post->ID);
      $excerpt = get_the_content();
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, $count);
      $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
      $excerpt = $excerpt.' <a href="'.$permalink.'">»</a>';
      return $excerpt;
    }

    When you want to call the excerpt just use
    <?php echo get_excerpt(100);?>
    Change the number to how many characters you want

    Thread Starter quiksilver189

    (@quiksilver189)

    No, not quite. I’m talking about the navigation on a post page that brings you to other post pages, not the link that brings you from an excerpt to the post that was excerpted from.

    This is the code that I’m looking to alter

    <div id="nav-above" class="navigation">
    					<div class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'twentyten' ) . '</span> %title' ); ?></div>
    					<div class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'twentyten' ) . '</span>' ); ?></div>
    				</div><!-- #nav-above -->

    Hello,

    This might not be an elegant solution, but I cobbled it together from various sources around the internet. I hope it helps.

    <div class="next">
    <?php $next_post = get_next_post();
     if (!empty( $next_post )):
     $nexty=$next_post->post_title;
    if (strlen($nexty) > 15){$newshort = substr($nexty,0,15).'...';}else{$newshort=$nexty;}
     endif; ?>
    
    <?php next_post_link('%link ›', $newshort ); ?>
     </div>

    Your next link will go from being:
    “This is the full title of the post >”
    to:
    “This is the full … >”

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limiting the amount of text generated by '%link'…’ is closed to new replies.