• ok im using this http://wiki.wordpress.org/Recent%20Posts and i want to know how to make it so it will only name part of the post title (some of the titles are long so it looks funny when it runs off) i would like it to look something like

    Drove up the califor….

    instead of

    Drove up the california coast line

    thanks guys for your help if you can tell me exactly how to do it (code to u se) it would be great

Viewing 4 replies - 1 through 4 (of 4 total)
  • <?php echo substr(get_the_title(), 0, [number of letters in the title]) . '...'; ?>

    Change:

    $post_title = stripslashes($post->post_title);

    to this slightly more complicated block of code:

    $post_title = stripslashes($post->post_title);
    $title_len = strlen(stripslashes($post_title));
    if(21 < $title_len) {
    $post_title = substr(stripslashes($post_title), 0, 20) . '...';

    That will truncate the title and add the "..." if the title is longer than 20 characters.
    }

    Nick has updated the code there to a plugin:
    http://mtdewvirus.com/code/wordpress-plugins/

    There is also coffee2code’s plugins one of which could help:
    http://www.coffee2code.com/wp-plugins/

    I was obviously in a hurry earlier. All those extra stripslashes() are not needed (and I jumped into the code with my final note):

    $post_title = stripslashes($post->post_title);
    $title_len = strlen($post_title);
    if(21 < $title_len) {
    $post_title = substr($post_title, 0, 20) . '...';
    }

    And yes, those plugins are worth a look.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘recent post’ is closed to new replies.