<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joshua's Life &#187; drupal node title length</title>
	<atom:link href="http://www.joshuaslife.com/tag/drupal-node-title-length/feed" rel="self" type="application/rss+xml" />
	<link>http://www.joshuaslife.com</link>
	<description>Joshua Heiland's life as a web developer</description>
	<lastBuildDate>Thu, 25 Feb 2010 07:15:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Limiting Node Title Lengths In Drupal</title>
		<link>http://www.joshuaslife.com/drupal/limiting-node-title-lengths-in-drupal</link>
		<comments>http://www.joshuaslife.com/drupal/limiting-node-title-lengths-in-drupal#comments</comments>
		<pubDate>Sat, 13 Dec 2008 05:51:10 +0000</pubDate>
		<dc:creator>Joshua Heiland</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[drupal node title length]]></category>

		<guid isPermaLink="false">http://www.joshuaslife.com/?p=51</guid>
		<description><![CDATA[<img src="http://www.joshuaslife.com/wp-content/uploads/dupal-icon.jpg" width="35" height="35" alt="" title="Drupal" /><br/>Im just wrapping up development on WinForAYear.com and because of how I&#8217;ve formatted the nodes, I needed a way to shorten the titles if they exceeded a set length.  This feature would come in handy in many situations, like presenting a table of stats where the title could easily overlap into another column.
Now you could [...]]]></description>
			<content:encoded><![CDATA[<img src="http://www.joshuaslife.com/wp-content/uploads/dupal-icon.jpg" width="35" height="35" alt="" title="Drupal" /><br/><p><span class="first-letter">Im</span> just wrapping up development on <a href="http://www.winforayear.com" target="_blank">WinForAYear.com</a> and because of how I&#8217;ve formatted the nodes, I needed a way to shorten the titles if they exceeded a set length.  This feature would come in handy in many situations, like presenting a table of stats where the title could easily overlap into another column.</p>
<p>Now you could easily edit the title css to include a set width with &#8220;overflow:hidden&#8221; hiding the excess, but then you would be left with abruptly ending titles with no indication that there is more.  However, if there were &#8220;&#8230;&#8221; attatched to the end of the shortened titles, things would be more clear.</p>
<p><strong>The Solution</strong><br />
Open up your node.tpl.php file in your drupal theme.  Look for this line:</p>
<blockquote><p>&lt;?php print $title; ?&gt;</p></blockquote>
<p>and replace it with:</p>
<blockquote><p>&lt;?php<br />
// if title is longer than 28 characters, cut off the rest and add &#8220;&#8230;&#8221;<br />
if(strlen($title) &gt; 28){ print substr($title, 0, 28).&#8221;&#8230;&#8221;;}<br />
else { print $title; }<br />
?&gt;</p></blockquote>
<p><strong>The Breakdown</strong></p>
<blockquote><p>if(strlen($title) &gt; 28)</p></blockquote>
<p>If the title is greater than 28 characters (including spaces).</p>
<blockquote><p>{print substr($title, 0, 28).&#8221;&#8230;&#8221;;}</p></blockquote>
<p>Display the first 28 characters of the node title and attatch &#8220;&#8230;&#8221; to the end.</p>
<blockquote><p>else { print $title; }</p></blockquote>
<p>Now we don&#8217;t want &#8220;&#8230;&#8221; being displayed if the title isn&#8217;t too long, so here we just display the title unchanged.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joshuaslife.com/drupal/limiting-node-title-lengths-in-drupal/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
