<?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>RLM &#187; Excerpts</title>
	<atom:link href="http://www.rlmseo.com/blog/category/wordpress/excerpts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rlmseo.com</link>
	<description></description>
	<lastBuildDate>Tue, 31 Jan 2012 03:37:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Changing Excerpt Size Dynamically</title>
		<link>http://www.rlmseo.com/blog/changing-excerpt-size-dynamically/</link>
		<comments>http://www.rlmseo.com/blog/changing-excerpt-size-dynamically/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 23:10:29 +0000</pubDate>
		<dc:creator>jcrens8392</dc:creator>
				<category><![CDATA[Excerpts]]></category>
		<category><![CDATA[excerpt]]></category>

		<guid isPermaLink="false">http://www.rlmseo.com/changing-excerpt-size-dynamically/</guid>
		<description><![CDATA[I needed to change the size of the post summary / excerpt depending on the length of the title for a recent project. The goal was to fit both the post title and excerpt within a fixed-size container, while being able to adjust for changing title and excerpt sizes from post to post. This is how I did it.]]></description>
			<content:encoded><![CDATA[<p>I was working on a custom WordPress blog design for a client and, unlike most blog designs, we needed to fit the post summary (or excerpt) into a fixed area. Traditional blog designs won&#8217;t break if the post excerpt exceeds a certain size, but in this case, we had to keep both the title, and the excerpt height no greater than the image as shown below.</p>
<p>We knew the image size, but the title and excerpt sizes were the variables here. We didn&#8217;t want to cut off the title, so we had to figure out a way to check how much space the title occupied, then figure out how much space was remaining for the excerpt. If the excerpt was larger than the space remaining, we needed to trim the excerpt toward the end and add [...] to indicate the excerpt was truncated.</p>
<p>The following photos are of the homepage layout&#8230;each post was shown on the homepage as one of these wide, image, title, and excerpt combinations.</p>
<p>The first photo below shows how we wanted the excerpts to be displayed. The second shows what happens if the excerpt isn&#8217;t truncated based on the title size&#8230;not good.</p>
<div id="attachment_1383" class="wp-caption aligncenter" style="width: 563px"><a href="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-excerpt-bad-overflow.gif" rel="wp-prettyPhoto[544]"><img src="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-excerpt-bad-overflow.gif" alt="WordPress excerpt not dynamically truncated" title="WordPress excerpt not dynamically truncated" width="553" height="198" class="size-full wp-image-1383" /></a><p class="wp-caption-text">Without dynamically truncating the excerpt, a long post title will make it overflow it&#039;s container</p></div>
<div id="attachment_1384" class="wp-caption aligncenter" style="width: 563px"><a href="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-excerpt-no-overflow.gif" rel="wp-prettyPhoto[544]"><img src="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-excerpt-no-overflow.gif" alt="Dynamically truncated WordPress post excerpt" title="Dynamically truncated WordPress post excerpt" width="553" height="119" class="size-full wp-image-1384" /></a><p class="wp-caption-text">Dynamically truncating allows us to account for varying title lengths to prevent excerpt overflow</p></div>
<p>This will require you to put your thinking cap on, so dig it out from under that pile of clothes, beer cans, or whatever it is you leave all around your house, and set it top of that little idea factory you call your head.</p>
<h2>The Code I Used</h2>
<p>Here&#8217;s the code I used to get it done&#8230;you&#8217;re welcome to copy this code, but be sure to read the rest of this post as you&#8217;ll have to change a few things depending on the font family and font sizes used on your blog.</p>
<pre>
&lt;?php
// Dynamically resize excerpt according to title length
$rem_len = &quot;&quot;; //clear variable
$title_len = strlen($post-&gt;post_title); //get length of title
if($title_len &lt;= 35){
	$rem_len=188; //calc space remaining for excerpt
}elseif($title_len &lt;= 70){
	$rem_len=146;
}elseif($title_len &lt;= 105){
	$rem_len=104;
}elseif($title_len &lt;= 140){
	$rem_len=62;
}
$trunc_ex = substr($post-&gt;post_excerpt, 0, $rem_len); //truncate excerpt to fit remaining space
if(strlen($trunc_ex) &lt; strlen($post-&gt;post_excerpt)) $trunc_ex = $trunc_ex . &quot; [...]&quot;;
echo &quot;&lt;p&gt;&quot; . $trunc_ex . &quot;&lt;/p&gt;&quot;; //display excerpt
?&gt;</pre>
<h2>Now the explanation</h2>
<p>First, I took the font used for post titles on the homepage and calculated (roughly) how many characters it took to fill out a full line within the space allocated. That number turned out to be about 35 characters per line.</p>
<div id="attachment_1386" class="wp-caption aligncenter" style="width: 542px"><a href="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-calculate-title-length.jpg" rel="wp-prettyPhoto[544]"><img src="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-calculate-title-length.jpg" alt="Calculating number of characters per line in the title" title="Calculating number of characters per line in the title" width="532" height="258" class="size-full wp-image-1386" /></a><p class="wp-caption-text">Calculating number of characters per line in the title resulted in 35</p></div>
<p>Then I did the same for the post excerpt font. Turns out that the post excerpt font takes up 42 characters per line.</p>
<div id="attachment_1387" class="wp-caption aligncenter" style="width: 542px"><a href="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-calculate-excerpt-length.jpg" rel="wp-prettyPhoto[544]"><img src="http://www.rlmseo.com/wp-content/uploads/2008/01/wordpress-calculate-excerpt-length.jpg" alt="Counting number of characters per line in the post excerpt" title="Counting number of characters per line in the post excerpt" width="532" height="258" class="size-full wp-image-1387" /></a><p class="wp-caption-text">Count number of characters per line in the post excerpt gave me 42</p></div>
<p>Then I figured, since every 35 characters in the title takes up one line, and 42 characters of the excerpt occupy a full line, then for every 35 characters in the post title, that was 42 more characters I&#8217;d have to truncate off the excerpt text.</p>
<p>You also have to consider the fact that the post title is a block level element. In other words, even if the post title only takes up half a line, the post excerpt won&#8217;t begin until the following line.</p>
<h2>How to Edit the Code for Your Blog</h2>
<p>So, to make it work for you, you need to figure out the maximum number of excerpt characters that will fit inside your div element along with 1 line of post title. For me that was 5.</p>
<p>Then edit the code I gave you above as follows:</p>
<p>Replace the number 35 in the following line with the number of characters per line for your title:</p>
<pre> if($title_len &lt;= 35){</pre>
<p>Then skip a line and replace the number 70 in the following line with 2 x the number of characters per line for your title:</p>
<pre>}elseif($title_len &lt;= 70){</pre>
<p>Then skip another line and replace the number 105 in the following line with 3 x the number of characters per line for your title (are you seeing a pattern here?):</p>
<pre> }elseif($title_len &lt;= 105){</pre>
<p>Then skip another line and replace the number  140 in the following line with 4 x the number of characters per line for your title:</p>
<pre> }elseif($title_len &lt;= 140){</pre>
<p>Now, you may want to keep going, I repeated this 4 times because I figured I could fit one line of excerpt in with 4 lines of title at the most.</p>
<p>Now you need to go back and remember the total number of excerpt characters you figured would fit inside that div element. Got that number in front of you? Good. Now you&#8217;ll need the number of characters per line for your excerpt font. Now subtract the number of characters per line from the total excerpt characters that could fit in the div element. Whatever that number comes to, put it in place of 188 in the following line of code from above:</p>
<pre> $rem_len=188; //calc space remaining for excerpt</pre>
<p>Now take the number of excerpt characters per line x 2 and subtract that from the total excerpt characters that would fit inside the div. Now put it in place of 146 in the following line of code from above:</p>
<pre> $rem_len=146;</pre>
<p>Now take the number of excerpt characters per line x 3 and subtract that from the total excerpt characters that would fit inside the div. Now put it in place of 104 in the following line of code from above:</p>
<pre> $rem_len=104;</pre>
<p>And finally, take the number of excerpt characters per line x 4 and subtract that from the total excerpt characters that would fit inside the div. Now put it in place of the 62 in the following line of code from above:</p>
<pre> $rem_len=62;</pre>
<p>That&#8217;s it. Now your excerpt should automatically resize itself depending on the length of the post title.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rlmseo.com/blog/changing-excerpt-size-dynamically/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Transform Your Read More Link With a Little Pizzaz</title>
		<link>http://www.rlmseo.com/blog/change-read-more-link/</link>
		<comments>http://www.rlmseo.com/blog/change-read-more-link/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 04:00:22 +0000</pubDate>
		<dc:creator>jcrens8392</dc:creator>
				<category><![CDATA[Excerpts]]></category>
		<category><![CDATA[Posts]]></category>
		<category><![CDATA[read more]]></category>

		<guid isPermaLink="false">http://www.rlmseo.com/change-read-more-link/</guid>
		<description><![CDATA[It's not the biggest change you can make, but changing the wording of your "read more" link can actually help your click-through rate.]]></description>
			<content:encoded><![CDATA[<p>Whether it be &#8220;[Read more &raquo;]&#8221; or the default &#8220;Read the rest of this entry &raquo;,&#8221; your read more link is probably boring and you may be missing out on ways to increase your click through rate by changing the wording of your &#8220;Read More&#8221; link.</p>
<p>Hey, <a href="http://www.copyblogger.com">Copyblogger</a> uses it, so it must work, right? Anyway, here&#8217;s a quick rundown of how to do it&#8230;</p>
<p>Open up <em>index.php</em> for your WordPress theme&#8230;as usual, use the default theme as a reference if you&#8217;re having trouble following along. Find the following line (it&#8217;s line #12 on the default theme):</p>
<pre>&lt;div class=&quot;entry&quot;&gt;
&lt;?php the_content(&#039;Read the rest of this entry &amp;raquo;&#039;); ?&gt;
&lt;/div&gt;</pre>
<p>The only thing you need to change is what&#8217;s between the single quotes of <em>the_content(&#8216;&#8230;&#8230;.&#8217;);</em> &#8211; now change it so it looks like this:</p>
<pre>&lt;div class=&quot;entry&quot;&gt;
&lt;?php the_content(&#039;Click to continue &amp;rarr;&#039;); ?&gt;
&lt;/div&gt;</pre>
<p>The &#8220;&amp;rarr;&#8221; part is just the <a title="ASCII Codes" href="http://www.ascii.cl/htmlcodes.htm">ascii code</a> for a right arrow. Now your <em>Read more</em> link will look like this:</p>
<p><a href="#">Click to continue &rarr;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rlmseo.com/blog/change-read-more-link/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

