<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>

<channel>
	<title>Understanding WordPress &#187; Coding</title>
	<atom:link href="http://www.understandingwordpress.com/blog/category/coding/feed" rel="self" type="application/rss+xml" />
	<link>http://www.understandingwordpress.com/blog</link>
	<description>Offering inexpensive online classes for all levels</description>
	<lastBuildDate>Fri, 05 Mar 2010 05:16:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<!-- podcast_generator="Blubrry PowerPress/1.0.9" mode="simple" entry="normal" -->
	<itunes:summary>Offering inexpensive online classes for all levels</itunes:summary>
	<itunes:author>Understanding WordPress</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.understandingwordpress.com/blog/wp-content/plugins/powerpress/itunes_default.jpg" />
	<itunes:owner>
		<itunes:name>Understanding WordPress</itunes:name>
		<itunes:email>frank@javascriptworkshop.com</itunes:email>
	</itunes:owner>
	<managingEditor>frank@javascriptworkshop.com (Understanding WordPress)</managingEditor>
	<itunes:subtitle>Offering inexpensive online classes for all levels</itunes:subtitle>
	<image>
		<title>Understanding WordPress &#187; Coding</title>
		<url>http://www.understandingwordpress.com/blog/wp-content/plugins/powerpress/rss_default.jpg</url>
		<link>http://www.understandingwordpress.com/blog/category/coding</link>
	</image>
		<item>
		<title>Highlighting Searched Text in Search Results</title>
		<link>http://www.understandingwordpress.com/blog/highlighting-searched-text-in-search-results.html</link>
		<comments>http://www.understandingwordpress.com/blog/highlighting-searched-text-in-search-results.html#comments</comments>
		<pubDate>Thu, 08 Oct 2009 18:13:00 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Customized Search]]></category>
		<category><![CDATA[Highlighting Search Results]]></category>

		<guid isPermaLink="false">http://www.understandingwordpress.com/blog/?p=74</guid>
		<description><![CDATA[I must admit that I&#8217;m not a big fan of the WordPress built-in search engine. One of its weakest features is the fact that searched text aren&#8217;t highlighted in the results, so the visitor is unable to see the searched text in the context of your article. Luckily, there&#8217;s a nice hack using regular expressions [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>I must admit that I&#8217;m not a big fan of the WordPress built-in search engine. One of its weakest features is the fact that searched text aren&#8217;t highlighted in the results, so the visitor is unable to see the searched text in the context of your article.</p>
<p>Luckily, there&#8217;s a nice hack using regular expressions to automatically highlight searched text in search results. This code has been created by Joost de Valk who blogs at <a target="_blank"  href="http://yoast.com/" onclick="pageTracker._trackPageview('/outgoing/yoast.com/?referer=');">www.yoast.com</a>.</p>
<p>1. Open your search.php file and find the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>2. Replace with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$keys</span><span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/('</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">')/iu'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'&lt;strong class=&quot;search-excerpt&quot;&gt;\0&lt;/strong&gt;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>3. Save the search.php file and open the style.css file. Append the following line to it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">strong<span style="color: #6666ff;">.search-excerpt</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">yellow</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>4. You&#8217;re done. Now, the searched text will be highlighted in your search results.</p>
<p><strong>How It Works:</strong></p>
<p>This code is using PHP regular expressions to find the searched terms in the text returned by WordPress. When an occurrence has been found, it is wrapped in a  HTML element. Then, I simply used CSS to define a yellow background to this element.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.understandingwordpress.com/blog/highlighting-searched-text-in-search-results.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code to Display the Most Recent Comments</title>
		<link>http://www.understandingwordpress.com/blog/code-to-display-the-most-recent-comments.html</link>
		<comments>http://www.understandingwordpress.com/blog/code-to-display-the-most-recent-comments.html#comments</comments>
		<pubDate>Mon, 17 Aug 2009 00:44:32 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Display Most Recent Comments]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.understandingwordpress.com/blog/?p=57</guid>
		<description><![CDATA[There are a few plugins that will retrieve the most comments. But if you want a little more control or like to get your hands dirty in a little PHP code, there is a code snippet that will do the trick: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>There are a <a target="_blank" href="http://wordpress.org/extend/plugins/get-recent-comments/" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/get-recent-comments/?referer=');">few plugins</a> that will retrieve the most comments. But if you want a little more control or like to get your hands dirty in a little PHP code, there is a code snippet that will do the trick:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt,
comment_approved, comment_type,comment_author_url, SUBSTRING (comment_content,1,30) AS com_excerpt
FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;comments</span>
LEFT OUTER JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> ON (<span style="color: #006699; font-weight: bold;">$wpdb-&gt;comments</span>.comment_post_ID = <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span>.ID)
WHERE comment_approved = '1' AND comment_type = '' AND post_password = ''
ORDER BY comment_date_gmt DESC LIMIT 10&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pre_HTML</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;li&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_author</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
   <span style="color: #0000ff;">&quot;#comment-&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_ID</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span>on &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> 
   <span style="color: #339933;">.</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">com_excerpt</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$post_HTML</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.understandingwordpress.com/blog/code-to-display-the-most-recent-comments.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
