<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>ThemeShaper Forums Topic: Set the excerpt length by sentence</title>
<link>http://themeshaper.com/forums/</link>
<description>Help In Shaping WordPress Themes</description>
<language>en</language>
<pubDate>Mon, 20 May 2013 01:27:33 +0000</pubDate>

<item>
<title>Chris on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12294</link>
<pubDate>Tue, 11 May 2010 14:47:15 +0000</pubDate>
<dc:creator>Chris</dc:creator>
<guid isPermaLink="false">12294@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Let me see, what I can do with Thematic itself. &#60;/p&#62;
&#60;p&#62;As long as you don't use any fancy things like lists, quotes, or similar at the beginning of your post, we can handle this with some additional code. Otherwise you are right with using a manual excerpt.&#60;/p&#62;
&#60;p&#62;Chris
&#60;/p&#62;</description>
</item>
<item>
<title>helgatheviking on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12287</link>
<pubDate>Tue, 11 May 2010 13:18:15 +0000</pubDate>
<dc:creator>helgatheviking</dc:creator>
<guid isPermaLink="false">12287@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;No worries.  I really appreciate your help.  Yes, that is what I am going for.  Very similar to the standard excerpt except that it doesn't cut off in the middle of a sentence with ...  I guess the easiest answer is to always write custom excerpts and that is probably a good practice anyway.
&#60;/p&#62;</description>
</item>
<item>
<title>Chris on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12282</link>
<pubDate>Tue, 11 May 2010 09:05:47 +0000</pubDate>
<dc:creator>Chris</dc:creator>
<guid isPermaLink="false">12282@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Sorry, my fault :)&#60;/p&#62;
&#60;p&#62;So .. the excerpt should have the look and feel of the standard excerpt, no markup, no images and so on? And it should have the 'sentence' functionality?
&#60;/p&#62;</description>
</item>
<item>
<title>helgatheviking on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12266</link>
<pubDate>Mon, 10 May 2010 15:27:46 +0000</pubDate>
<dc:creator>helgatheviking</dc:creator>
<guid isPermaLink="false">12266@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Hi Chris,&#60;/p&#62;
&#60;p&#62;Thank you for your effort!  What you have written seems to exactly replicate the FancyExcerpt plugin.. and the images are still included in the excerpt instead of being escaped.  Am I supposed to have the fancyexcerpt plugin enabled?  I tried that and it produced a fatal error.
&#60;/p&#62;</description>
</item>
<item>
<title>Chris on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12244</link>
<pubDate>Sun, 09 May 2010 09:31:53 +0000</pubDate>
<dc:creator>Chris</dc:creator>
<guid isPermaLink="false">12244@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Check if this is working for you (needs to be copied into your child theme's functions.php):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;class fancy_excerpt {
	/**
	 * trim_excerpt()
	 *
	 * @param string $text
	 * @return string $text
	 **/

	function trim_excerpt($text) {

		$max_words = 30;
		$max_words = apply_filters(&#38;#39;fancy_excerpt_words&#38;#39;, $max_words);

		$text = trim($text);

		if ( $text &#124;&#124; !in_the_loop() )
			return wp_trim_excerpt($text);

		$more = sprintf(__(&#38;#39;Read more on %s...&#38;#39;, &#38;#39;fancy-excerpt&#38;#39;), get_the_title());

		$more = apply_filters(&#38;#39;fancy_excerpt_more&#38;#39;, $more);

		$text = get_the_content($more);
		$text = str_replace(array(&#38;quot;\r\n&#38;quot;, &#38;quot;\r&#38;quot;), &#38;quot;\n&#38;quot;, $text);
		#dump(esc_html($text));

		if ( !preg_match(&#38;quot;&#124;&#38;quot; . preg_quote($more, &#38;#39;&#124;&#38;#39;) . &#38;quot;&#38;lt;/a&#38;gt;$&#124;&#38;quot;, $text)
			&#38;#38;&#38;#38; count(preg_split(&#38;quot;~\s+~&#38;quot;, trim(strip_tags($text)))) &#38;gt; $max_words
		) {
			global $escape_fancy_excerpt;
			$escape_fancy_excerpt = array();

			if (apply_filters(&#38;#39;fancy_excerpt_escape&#38;#39;, true)) {

				$text = fancy_excerpt::escape($text);

			}

			$bits = preg_split(&#38;quot;/(&#38;lt;(?:h[1-6]&#124;p&#124;ul&#124;ol&#124;li&#124;dl&#124;dd&#124;table&#124;tr&#124;pre&#124;blockquote)\b[^&#38;gt;]*&#38;gt;&#124;\n{2,})/i&#38;quot;, $text, null, PREG_SPLIT_DELIM_CAPTURE);
			$text = &#38;#39;&#38;#39;;
			$length = 0;

			foreach ( $bits as $bit ) {
				$text .= $bit;
				$bit_count = trim(strip_tags($bit));
				if ( $bit_count === &#38;#39;&#38;#39; )
					continue;
				$count += count(preg_split(&#38;quot;~\s+~&#38;quot;, $bit_count));

				if ( $count &#38;gt; $max_words )
					break;
			}

			$text = fancy_excerpt::unescape($text);

			$text = force_balance_tags($text);

			$text .= &#38;quot;\n\n&#38;quot;
				. &#38;#39;&#38;lt;p&#38;gt;&#38;#39;
				. apply_filters(&#38;#39;the_content_more_link&#38;#39;,
					&#38;#39;&#38;lt;a href=&#38;quot;&#38;#39;. esc_url(apply_filters(&#38;#39;the_permalink&#38;#39;, get_permalink())) . &#38;#39;&#38;quot; class=&#38;quot;more-link&#38;quot;&#38;gt;&#38;#39;
					. $more
					. &#38;#39;&#38;lt;/a&#38;gt;&#38;#39;)
				. &#38;#39;&#38;lt;/p&#38;gt;&#38;#39; . &#38;quot;\n&#38;quot;;
		}

		$text = apply_filters(&#38;#39;the_content&#38;#39;, $text);

		return apply_filters(&#38;#39;wp_trim_excerpt&#38;#39;, $text, &#38;#39;&#38;#39;);
	} # trim_excerpt()

	/**
	 * escape()
	 *
	 * @param string $text
	 * @return string $text
	 **/

	function escape($text) {
		global $escape_fancy_excerpt;

		if ( !isset($escape_fancy_excerpt) )
			$escape_fancy_excerpt = array();

		foreach ( array(
			&#38;#39;blocks&#38;#39; =&#38;gt; &#38;quot;/
				&#38;lt;\s*(script&#124;style&#124;object&#124;textarea)(?:\s.*?)?&#38;gt;
				.*?
				&#38;lt;\s*\/\s*\\1\s*&#38;gt;
				/isx&#38;quot;,
			) as $regex ) {
			$text = preg_replace_callback($regex, array(&#38;#39;fancy_excerpt&#38;#39;, &#38;#39;escape_callback&#38;#39;), $text);
		}

		return $text;
	} # escape()

	/**
	 * escape_callback()
	 *
	 * @param array $match
	 * @return string $text
	 **/

	function escape_callback($match) {
		global $escape_fancy_excerpt;

		$tag_id = &#38;quot;----escape_fancy_excerpt:&#38;quot; . md5($match[0]) . &#38;quot;----&#38;quot;;
		$escape_fancy_excerpt[$tag_id] = $match[0];

		return $tag_id;
	} # escape_callback()

	/**
	 * unescape()
	 *
	 * @param string $text
	 * @return string $text
	 **/

	function unescape($text) {
		global $escape_fancy_excerpt;

		if ( !$escape_fancy_excerpt )
			return $text;

		$unescape = array_reverse($escape_fancy_excerpt);

		return str_replace(array_keys($unescape), array_values($unescape), $text);
	} # unescape()
} # fancy_excerpt

remove_filter(&#38;#39;get_the_excerpt&#38;#39;, &#38;#39;wp_trim_excerpt&#38;#39;);
add_filter(&#38;#39;get_the_excerpt&#38;#39;, array(&#38;#39;fancy_excerpt&#38;#39;, &#38;#39;trim_excerpt&#38;#39;), 0);
function my_words() {
	return 20;
}
add_filter(&#38;#39;fancy_excerpt_words&#38;#39;, &#38;#39;my_words&#38;#39;);
function no_escape() {
	return false;
}
add_filter(&#38;#39;fancy_excerpt_escape&#38;#39;, &#38;#39;no_escape&#38;#39;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Chris
&#60;/p&#62;</description>
</item>
<item>
<title>helgatheviking on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12212</link>
<pubDate>Fri, 07 May 2010 12:39:40 +0000</pubDate>
<dc:creator>helgatheviking</dc:creator>
<guid isPermaLink="false">12212@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;That would be &#60;em&#62;exactly&#60;/em&#62; what I am after.
&#60;/p&#62;</description>
</item>
<item>
<title>Chris on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12205</link>
<pubDate>Fri, 07 May 2010 08:25:11 +0000</pubDate>
<dc:creator>Chris</dc:creator>
<guid isPermaLink="false">12205@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Mmmh .. would the Fancy Excerpts without the 'escaping' part be ok for you? Would add a few filters to control 'escaping' and 'number of sentences'. This could be integrated in your child theme.&#60;/p&#62;
&#60;p&#62;Chris
&#60;/p&#62;</description>
</item>
<item>
<title>helgatheviking on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12154</link>
<pubDate>Wed, 05 May 2010 21:24:30 +0000</pubDate>
<dc:creator>helgatheviking</dc:creator>
<guid isPermaLink="false">12154@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Hi Chris,&#60;/p&#62;
&#60;p&#62;I've toyed w/ just about every excerpt plugin there is.  Fancy Excerpt is definitely the closest- b/c of the sentence-awareness - but I don't want it escaping images and other things that end up looking goofy w/ thumbnails, and there is no way to toggle that on/off like in Advanced Excerpts. If they could get together and have a child called Advanced Fancy Excerpt that would be brilliant.
&#60;/p&#62;</description>
</item>
<item>
<title>Chris on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12148</link>
<pubDate>Wed, 05 May 2010 20:23:24 +0000</pubDate>
<dc:creator>Chris</dc:creator>
<guid isPermaLink="false">12148@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;why don't you integrate Fancy Excerpt into your theme?&#60;/p&#62;
&#60;p&#62;:)&#60;/p&#62;
&#60;p&#62;Chris
&#60;/p&#62;</description>
</item>
<item>
<title>helgatheviking on "Set the excerpt length by sentence"</title>
<link>http://themeshaper.com/forums/topic/set-the-excerpt-length-by-sentence#post-12102</link>
<pubDate>Tue, 04 May 2010 22:41:00 +0000</pubDate>
<dc:creator>helgatheviking</dc:creator>
<guid isPermaLink="false">12102@http://themeshaper.com/forums/</guid>
<description>&#60;p&#62;Is it possible to make the excerpt sentence aware w/o a plugin?  I've seen the snippets for setting length based on words, but was wondering if it wouldn't be too hard to extrapolate out to sentences... which seems more logical to me.
&#60;/p&#62;</description>
</item>

</channel>
</rss>
