<?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>excerpt &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/excerpt/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Sat, 08 Oct 2011 18:56:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>Get the WordPress-excerpt by specifying a maximum amount of characters</title>
		<link>https://blog.blackbam.at/2011/05/15/get-the-wordpress-excerpt-by-specifying-a-maximum-amount-of-characters/</link>
					<comments>https://blog.blackbam.at/2011/05/15/get-the-wordpress-excerpt-by-specifying-a-maximum-amount-of-characters/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sun, 15 May 2011 14:41:23 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[excerpt]]></category>
		<category><![CDATA[get_the_excerpt]]></category>
		<category><![CDATA[the_excerpt]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1389</guid>

					<description><![CDATA[A lot of sites want WordPress excerpts to have an accurate length to fit into a specified number of text lines. This can be required for design reasons, for example. The default WordPress excerpt length is managed by a given amount of words (default 70), which can be very imprecicsly when it comes to the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A lot of sites want WordPress excerpts to have an accurate length to fit into a specified number of text lines. This can be required for design reasons, for example. The default WordPress excerpt length is managed by a given amount of words (default 70), which can be very imprecicsly when it comes to the actual length. Using the following function, you can get the excerpt by defining an desired amount of characters:</p>
<pre lang="php">
// define the desired amount of characters
$numberOfChars = 140;

// call the function
the_excerpt_max_charlength($numberOfChars);

// the function - copy this to the functions.php-file in your theme for example
function the_excerpt_max_charlength($charlength) {
   $excerpt = get_the_excerpt();
   $charlength++;
   if(strlen($excerpt)>$charlength) {
       $subex = substr($excerpt,0,$charlength-5);
       $exwords = explode(" ",$subex);
       $excut = -(strlen($exwords[count($exwords)-1]));
       if($excut<0) {
            echo substr($subex,0,$excut);
       } else {
       	    echo $subex;
       }
       echo "[...]";
   } else {
	   echo $excerpt;
   }
}
</pre>
<p>
With a slight differentiation this function can not only be used for excerpt, but for a very general way to limit the words of a PHP string by specifying a maximum amount of characters. This is the function for general use:<br />
</p>
<pre lang="php">
// Shorten a String pattern to a maximum of characters without breaking words, by giving a String, maximum length and closing pattern if true
function cis_limit_words($pattern,$charlength=200,$after=" [...]") {
   $charlength++;
   if(strlen($pattern)>$charlength) {
       $subex = substr($pattern,0,$charlength-5);
       $exwords = explode(" ",$subex);
       $excut = -(strlen($exwords[count($exwords)-1]));
       if($excut<0) {
            echo substr($subex,0,$excut);
       } else {
            echo $subex;
       }
       echo $after;
   } else {
    echo $pattern;
   }
}
</pre>
<p>Because it proved to be useful I also <a href="http://codex.wordpress.org/Function_Reference/get_the_excerpt">provided this to the codex</a>, improvements are welcome.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F05%2F15%2Fget-the-wordpress-excerpt-by-specifying-a-maximum-amount-of-characters%2F&#038;title=Get%20the%20WordPress-excerpt%20by%20specifying%20a%20maximum%20amount%20of%20characters" data-a2a-url="https://blog.blackbam.at/2011/05/15/get-the-wordpress-excerpt-by-specifying-a-maximum-amount-of-characters/" data-a2a-title="Get the WordPress-excerpt by specifying a maximum amount of characters"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/05/15/get-the-wordpress-excerpt-by-specifying-a-maximum-amount-of-characters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
