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!
Edit:
$title = the_title('', '', false);
if(strlen($title) > $max_len)
{
echo substr($title, 0, $max_length) . "...";
}
else
{
echo $title
}
should work for you.
You can use echo substr(get_the_title(), 0, 50)
to show the first 50 chars from the title, or add a more advanced function so you don't cut words: Making sure PHP substr finishes on a word not a character