0

Just wondering if someone can assist me with the following issue.

On the HOME page of my site I'm displaying 3 Blog posts from the Wordpress Blog site I have intergrated into the website; therefore I have made the index page dynamic and I've added the following:

<div id="from-blog">
    <h2>Latest Blog Posts</h2>
    <ul>
          <?php while (have_posts()): the_post(); ?>
        <li class="latest-entry-front">
              <span class="post-date">
                <span class="date-text">
                  <span class="month"><?php the_time('M') ?></span><br/>
                  <span class="day"><?php the_time('d') ?></span>
                </span>
              </span>
            <a href="<?php the_permalink(); ?>" title="Read full post"><?php the_title(); ?></a></li>
              <?php endwhile; ?>
        </ul>
    </div>

The issue here is that the posts are displaying the full blog title which is looking messy of it was a long Blog post title; therefore is there a way I can trim it to only display a maximum amount of characters and then [...] after it or ...

Any help much appreciated!

Bill Johnson
  • 303
  • 1
  • 6
  • 13

1 Answers1

0

Edit:

$title = the_title('', '', false);    
if(strlen($title) > $max_len)
{
  echo substr($title, 0, $max_length) . "...";
}
else
{
  echo $title
}

should work for you.

http://php.net/manual/en/function.substr.php

Richard Key
  • 103
  • 5
  • Sure Can Bill. In wordpress, you just replace $title with the_title('', '', false) or just create a variable: $title = the_title('', '', false); http://codex.wordpress.org/Function_Reference/the_title Sorry, can't post code in here for some reason. – Richard Key Nov 24 '10 at 23:14
  • Okay, I only want to trim the length on the index page which is outside of the Wordpress Blog and simply displays 3 posts; therefore is there not a way I can do this on the page and within the code I have? Thanks – Bill Johnson Nov 24 '10 at 23:34
  • You just replace your call the the_title() with the code provided. You could make the call like Vlad has, which will trim the title down to 50 no matter what, but that will not add the "..." if your title is longer than 50, it just trims the title. Does this make sense? – Richard Key Nov 24 '10 at 23:40
  • You know bill, I am not quite sure on that one. As you can see, I am quite new to this as well. I would appreciate at least a vote up though. – Richard Key Nov 25 '10 at 12:56