<?php if (strlen($post->post_title) > 40) { echo substr(the_title($before = '', $after = '', FALSE), 0, 40) . '...'; } else { the_title(); } ?>