subscribe

Here are some services that Yellow Bird Design finds helpful. If possible we host all of our sites with Host Gator because they are reliable and affordable. We use the Firefox web browser because it is more secure, faster and it adheres to W3C web standards.

Pricing Guide

Follow Yellow Bird's motto and stay current! This is our design blog. We post photoshop tutorials, design news and maybe some stuff we find funny. Sign up for our RSS feed or just come back and visit our site again.

Archive for January, 2008

How to truncate your title and your post text in Word Press with two plugins

Sunday, January 20th, 2008

I had a very long day today trying to track down the exact plugin combination needed to truncate both the title and text for posts in Word Press. That may sound like a weird need but I am working on this site where I need very uniform post for layout purposes and since random users can post whatever they want the only way to control height of each post was to truncate both the title and the post. Here is the site I am working on (it is still in development so a lot of stuff is broken, DON’T JUDGE ME! ;P).The plugin combination that I used is one part WP limit post automatically and one part iMP Limiter. Limit post automatically is awesome. The options are easily set in the WordPress admin panel to meet pretty much any truncating option you might need.

The second part wasn’t so easy.If you search iMP Limiter in google you will find a ton of results, but every site links to: http://www.inmypad.com/2006/12/wordpress-plugins-imp-limiter/That is a big fat 404. It turns out that this developer lost their database and you can’t download the plugin anymore from his site. So I thought for sure there was another source. There wasn’t. After like three hours I stooped to searching for open plugins directories through google, I am not going to name anyone. I went down the list of results and emailed all the contact emails on the sites. Out of the forum postings, emails to my networks and random emails to open directories I was snooping, I finally got an email back, and this kind soul provided me with the plugin. So no one else has to do this I am going to offer this plugin here:iMP Limiter (right click, save link as) I was able to find some instructions on how to use the plugin at some other random site but what was most important in the plugin were a few lines of code which decide whether you truncate the title or the post text.

The first step to using this plugin is replacing either, <?php the_content(); ?> or <?php the_title(); ?> with one of the lines of code below depending on whether you want to truncate by character count or word count.<?php iMP_Limit_Char($max_char='', $more_text=''); ?> // Use this to limit characters with default parameters.<?php iMP_Limit_Word($max_word='', $more_text=''); ?> // Use this to limit words with default parameters.

After you have added the code above to your index.php you to look below where there are two functions, one if you want to truncate based on character count and one based on word count. My code is set up to truncate the title. If you want to set it for the content you just have to replace “title” with “content” in the spots where “title” is bold.

function iMP_Limit_Char($max_char = 10, $more_text = ‘…’, $more_link_text = ”, $limit_type = ‘title‘) {if ($limit_type == ‘title’) { $limiter = get_the_title(); }else { $limiter = get_the_content(); }$limiter = apply_filters('the_title‘, $limiter);$limiter = strip_tags(str_replace(’]]>’, ‘]]>’, $limiter));if (strlen($limiter) > $max_char) {echo substr($limiter, 0, $max_char+1);echo $more_text;if ($more_link_text != '') {echo ' <a href="';echo the_permalink();echo '">'.$more_link_text.'</a>';}} else {echo $limiter;}}function iMP_Limit_Word($max_word = 40, $more_text = ‘…’, $more_link_text = ”, $limit_type = ‘title‘) {if ($limit_type == ‘title’) { $limiter = get_the_title(); }else { $limiter = get_the_content(); }$limiter = apply_filters('the_title‘, $limiter);$limiter = strip_tags(str_replace(’]]>’, ‘]]>’, $limiter));$trim = explode(' ', $limiter);if(count($trim) > $max_word) {$l = $max_word;for ($i=0; $i<=$l ; $i++) $output .= $trim[$i] . ' ';echo $output;echo $more_text;if ($more_link_text != '') {echo ' <a href="';echo the_permalink();echo '">'.$more_link_text.'</a>';}} else {echo $limiter;}}

I hope that this helps. I am not a developer/programmer I just design, code XHTML/CSS and hack stuff people have already programmed. Email me if you want, I will help as much as I can.