<?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>WP Garage &#187; Code Snippets</title>
	<atom:link href="http://wpgarage.com/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpgarage.com</link>
	<description>wordpress tricks, hacks, and tips</description>
	<lastBuildDate>Wed, 03 Mar 2010 14:47:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Display sticky post and exclude it from recent posts list in WordPress</title>
		<link>http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/</link>
		<comments>http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 13:30:03 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[exclude]]></category>
		<category><![CDATA[recent posts]]></category>
		<category><![CDATA[sticky posts]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wpgarage.com/?p=592</guid>
		<description><![CDATA[<p class="dropcap-first">We were working on a WordPress site that needed to display a sticky post at the top of the blog page with one style, and then below it a list of the most recent posts with a completely different style.</p>
<p>I realize that you can just style the sticky post ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">We were working on a WordPress site that needed to display a sticky post at the top of the blog page with one style, and then below it a list of the most recent posts with a completely different style.</p>
<p>I realize that you can just style the sticky post using the sticky-related classes provided by WordPress:</p>
<blockquote><p>&lt;div &lt;?php post_class(); ?&gt;&gt; and .sticky class</p></blockquote>
<p>but I needed to have design elements appear in between the sticky post and the rest of the recent posts, and the recent posts needed to have a completely different design than the sticky. Therefore I decided to go with a 2 loop solution. Once we were using two loops, we had to also make sure that sticky post did not repeat itself and appear in the list of recent posts following it.</p>
<p><a href="http://www.nathanrice.net/blog/definitive-sticky-posts-guide-for-wordpress-27/">Nathan Rice</a> provides a lot of useful information about sticky posts but I couldn&#8217;t get the code he posted to work properly. So I went on a hunt to figure it out.</p>
<h2>How to display a sticky post</h2>
<p>The best solution I found for how to display a WordPress sticky post was a <a href="http://justintadlock.com/archives/2009/03/28/get-the-latest-sticky-posts-in-wordpress#comment-113133">comment </a>by <cite title="http://www.ethymos.com.br"></cite><a title="Eduardo" rel="external nofollow" href="http://www.ethymos.com.br/">Eduardo</a> on Justin Tadlock&#8217;s post <a title="Get the latest sticky posts in WordPress" href="http://justintadlock.com/archives/2009/03/28/get-the-latest-sticky-posts-in-wordpress">Get the Latest Sticky Post</a>. He gave the following code:</p>
<blockquote><p>&lt;?php<br />
$sticky = get_option( &#8217;sticky_posts&#8217; );<br />
query_posts( array( &#8216;post__in&#8217; =&gt; $sticky, &#8216;caller_get_posts&#8217; =&gt; 1, &#8216;orderby&#8217; =&gt; ID, &#8217;showposts&#8217; =&gt; 2 ) );<br />
?&gt;<br />
&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;<br />
&lt;a href=&#8221;&lt;?php the_permalink(); ?&gt;&#8221; rel=&#8221;bookmark&#8221; title=&#8221;Permanent Link to &lt;?php the_title(); ?&gt;&#8221;&gt;<br />
&lt;?php endwhile;?&gt;</p>
<p>&lt;?php endif; ?&gt;</p></blockquote>
<p>It worked very nicely.</p>
<h2>How to exclude sticky posts from a list of recent posts</h2>
<p>I then wanted to show a list of 3 recent posts that excluded the post that had been defined as sticky. After many trials and errors with different solutions posted around the web, I finally found one that worked on the <a href="http://wordpress.org/support/topic/338776">WordPress Support Forum.</a></p>
<blockquote><p>&lt;?php $sticky = get_option(&#8217;sticky_posts&#8217;) ;</p>
<p>$post_to_exclude[] = $sticky[0];</p>
<p>$args=array(<br />
&#8216;caller_get_posts&#8217;=&gt;1,<br />
&#8217;showposts&#8217;=&gt;2,<br />
&#8216;post__not_in&#8217;=&gt; $post_to_exclude,<br />
);</p>
<p>query_posts($args); ?&gt;</p>
<p>&lt;h2&gt;&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;/h2&gt;</p>
<p>&lt;?php while (have_posts()) : the_post();  ?&gt;</p>
<p>&lt;?php endwhile;?&gt;</p></blockquote>
<p>So there you have it: a workable way to have a WordPress sticky post with one style, and a list of recent posts excluding the sticky post with a completely different style below the sticky post.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fdisplay-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress%2F&amp;title=Display+sticky+post+and+exclude+it+from+recent+posts+list+in+WordPress" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to list the 4 latest posts with only one post per author in WordPress</title>
		<link>http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/</link>
		<comments>http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 13:05:00 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[recent posts]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/</guid>
		<description><![CDATA[<p class="dropcap-first">Recently, one site we were working on needed a sidebar that would show the 4 most recent posts on the site. But here’s the catch: they wanted only one post per author. And, each author had to have the role of “author” as opposed to contributor or admin.</p>
<p>The site ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Recently, one site we were working on needed a sidebar that would show the 4 most recent posts on the site. But here’s the catch: they wanted only one post per author. And, each author had to have the role of “author” as opposed to contributor or admin.</p>
<p>The site in question is still in Beta, so I can’t give out the link yet. But here’s a snapshot to give you a better idea of what we were going for.</p>
<p><a href="http://wpgarage.com/wp-content/uploads/2009/09/wpgblogs.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="wpgblogs" src="http://wpgarage.com/wp-content/uploads/2009/09/wpgblogs_thumb.jpg" border="0" alt="wpgblogs" width="192" height="244" /></a></p>
<p>We also used the plugin <a href="http://wordpress.org/extend/plugins/user-photo/">User Photo</a> to show each author’s thumbnail, which I have come to love and recommend.</p>
<p>Thanks to <a href="http://www.marksw.com/blog/wordpress/">Mark Kaplun</a> for this great solution:</p>
<p>Open your Sidebar.php file and add the following:</p>
<p>Please note: this code uses the plugin Limit Posts to create excerpts. But you can substitute that snippet with any type of excerpt code.</p>
<p>&lt;?php $authors = get_users_of_blog(); ?&gt;</p>
<p>&lt;?php<br />
$latest_posts = array();<br />
foreach ( $authors as $author ) {<br />
$user = new WP_User( $author-&gt;ID );<br />
if ($user-&gt;has_cap(&#8216;level_7&#8242;))<br />
continue;<br />
$ps = get_posts(&#8216;numberposts=1&amp;post_type=post&amp;author=&#8217; . $author-&gt;ID . &#8216;&amp;cat=-9,-3&#8242;);<br />
foreach ($ps as $p) {<br />
$latest_posts[$p-&gt;post_date] = $p;<br />
}<br />
}<br />
krsort($latest_posts);<br />
?&gt;<br />
&lt;?php //query_posts(&#8216;author=&#8217; . $author-&gt;ID . &#8216;&amp;showposts=1&amp;cat=-9,-3&#8242;); ?&gt;<br />
&lt;?php<br />
$counter =0;<br />
foreach ($latest_posts as $post) {<br />
$counter++;<br />
if ($counter &gt; 4)<br />
break;<br />
setup_postdata($post);<br />
?&gt;</p>
<p>&lt;?php // while (have_posts()) : the_post(); ?&gt;</p>
<p>&lt;li&gt;<br />
&lt;?php userphoto_the_author_thumbnail(); ?&gt;<br />
&lt;span class=&#8221;blogauthor&#8221;&gt; &lt;?php the_author_posts_link(); ?&gt; &lt;/span&gt;<br />
&lt;div class=&#8221;blog&#8221;&gt;    &lt;a title=&#8221;Permanent Link to &lt;?php the_title(); ?&gt;&#8221; href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; rel=&#8221;bookmark&#8221;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/div&gt;<br />
&lt;br /&gt;</p>
<p>&lt;?php  the_content_limit(&#8216;55,read more&#8217;); ?&gt; &lt;strong&gt;&lt;a title=&#8221;Permanent Link to &lt;?php the_title(); ?&gt;&#8221; href=&#8221;&lt;?php the_permalink() ?&gt;&#8221;&gt;Read more&lt;/a&gt;   &lt;/strong&gt;<br />
&lt;/li&gt;<br />
&lt;?php } ?&gt;</p>
<p>&lt;?php // }; ?&gt;</p>
<p>The End. Yay code!</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Flist-4-latest-posts-with-only-one-post-per-author%2F&amp;title=How+to+list+the+4+latest+posts+with+only+one+post+per+author+in+WordPress" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Customize Multiple Search Result Pages in Wordpress</title>
		<link>http://wpgarage.com/code-snippets/how-to-customize-multiple-search-result-pages-in-wordpress/</link>
		<comments>http://wpgarage.com/code-snippets/how-to-customize-multiple-search-result-pages-in-wordpress/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 07:26:02 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[WordPress as CMS]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[Pages]]></category>
		<category><![CDATA[results]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/?p=498</guid>
		<description><![CDATA[<p class="dropcap-first">In the previous post, we discussed how to hack the search function in Wordpress to have an additional search form that would search  subcategories. Now that you have 2 or more search forms on your site, you might need to customize the search results. Thanks to this solution, I ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">In the previous post, we discussed how to <a href="http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/">hack the search function</a> in Wordpress to have an additional search form that would search  subcategories. Now that you have 2 or more search forms on your site, you might need to customize the search results. Thanks to <a href="http://www.rob-barrett.com/post/multiple-search-results-pages-within-one-wordpress-site">this solution</a>, I learned how to create multiple search result pages.</p>
<p>Let&#8217;s say we have 2 search forms on our site:</p>
<ol>
<li>General Site-Wide Search</li>
<li>Recipe Search &#8211; searches subcategories of the Recipe Category</li>
</ol>
<p>The first thing we need to do is tweak the search.php template to use it as a filter that will recognize if a search is coming from the Site-Wide search form or the Recipe Search form.</p>
<p><strong>1. Open Search.php</strong> and delete everything.  Add the following code:</p>
<blockquote><p>&lt;?php<br />
/* Template Name: Search Results */<br />
$search_refer = $_GET["site_section"];<br />
if ($search_refer == &#8216;recipe&#8217;) { load_template(TEMPLATEPATH . &#8216;/recipe-search.php&#8217;); }<br />
elseif ($search_refer == &#8217;site-search&#8217;) { load_template(TEMPLATEPATH . &#8216;/site-search.php&#8217;); }; ?&gt;</p></blockquote>
<p><strong>2. Open Header.php</strong> or wherever the General Site-Wide Search Form is located and add this line:</p>
<blockquote><p>&lt;input type=&#8221;hidden&#8221; name=&#8221;site_section&#8221; value=&#8221;site-search&#8221; /&gt;</p></blockquote>
<p><strong>The Site-Wide Search form will look something like this:</strong></p>
<blockquote><p>&lt;form method=&#8221;get&#8221; id=&#8221;searchform&#8221; action=&#8221;&lt;?php bloginfo(&#8216;home&#8217;); ?&gt;/&#8221;&gt;<br />
&lt;div id=&#8221;search&#8221;&gt;<br />
&lt;input type=&#8221;text&#8221; value=&#8221; &#8221; onclick=&#8221;this.value=&#8221;;&#8221; name=&#8221;s&#8221; id=&#8221;s&#8221; /&gt;<strong><br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;site_section&#8221; value=&#8221;site-search&#8221; /&gt;</strong><br />
&lt;input name=&#8221;" type=&#8221;image&#8221; src=&#8221;&lt;?php bloginfo(&#8217;stylesheet_directory&#8217;); ?&gt;/styles/&lt;?php echo &#8220;$style_path&#8221;; ?&gt;/search.gif&#8221; value=&#8221;Go&#8221; /&gt;<br />
&lt;/div&gt;&lt;!&#8211;/search &#8211;&gt;<br />
&lt;/form&gt;</p></blockquote>
<p><strong>3. </strong><strong>Open Recipes.php</strong> or wherever your second search is and insert this line:</p>
<blockquote><p><strong>&lt;input type=&#8221;hidden&#8221; name=&#8221;site_section&#8221; value=&#8221;recipe&#8221; /&gt; </strong></p></blockquote>
<p>You can change the value &#8220;recipe&#8221; to whatever suits your needs. Just make sure it matches the value in search.php.</p>
<p><strong>The Recipe Search form for your second search</strong> <strong>will look something like this</strong>. In my case, this second search is meant to search the subcategories of the Recipe category.  See my previous post to learn about<a href="http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/"> hacking the search function to search subcategories.</a></p>
<blockquote><p>&lt;form method=&#8221;get&#8221; id=&#8221;rsearchform&#8221; action=&#8221;&lt;?php bloginfo(&#8216;home&#8217;); ?&gt;/&#8221;&gt;<br />
&lt;div id=&#8221;rsearch&#8221;&gt;<br />
&lt;input type=&#8221;text&#8221; value=&#8221;Recipe Search&#8230; &#8221; onclick=&#8221;this.value=&#8221;;&#8221; name=&#8221;s&#8221; id=&#8221;rs&#8221; /&gt;<br />
&lt;?php $categories = get_categories(&#8216;child_of=11&#8242;);<br />
$catlist = &#8221;;<br />
foreach ($categories as $cat) {<br />
$catlist.= $cat-&gt;cat_ID.&#8217;,';<br />
}<br />
$catlist.&#8217;11&#8242;;<br />
?&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;cat&#8221; value=&#8221;&lt;?php echo &#8220;$catlist&#8221;?&gt;&#8221; /&gt;<br />
<strong>&lt;input type=&#8221;hidden&#8221; name=&#8221;site_section&#8221; value=&#8221;recipe&#8221; /&gt; </strong><br />
&lt;input name=&#8221;" type=&#8221;image&#8221; src=&#8221;&lt;?php bloginfo(&#8217;stylesheet_directory&#8217;); ?&gt;/styles/&lt;?php echo &#8220;$style_path&#8221;; ?&gt;/search.gif&#8221; value=&#8221;Go&#8221; /&gt;<br />
&lt;/div&gt;&lt;!&#8211;/search &#8211;&gt;<br />
&lt;/form&gt;</p></blockquote>
<p><strong>4. Customize the Search Results Templates</strong></p>
<p>If you recall, in step 1, we added the following to the search.php page.</p>
<blockquote><p>if ($search_refer == &#8216;recipe&#8217;) { load_template(TEMPLATEPATH . &#8216;/recipe-search.php&#8217;); }<br />
elseif ($search_refer == &#8217;site-search&#8217;) { load_template(TEMPLATEPATH . &#8216;/site-search.php&#8217;); }; ?&gt;</p></blockquote>
<p>Create recipe-search.php (or whatever you named this template) and customize the layout of the results page to your liking. You can use index.php to start with and customize from there.</p>
<p>Create site-search.php (or whatever you named this template) and customize the layout of the results page to your liking. You can use index.php to start with and customize from there.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-customize-multiple-search-result-pages-in-wordpress%2F&amp;title=How+to+Customize+Multiple+Search+Result+Pages+in+Wordpress" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/how-to-customize-multiple-search-result-pages-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Hack the Wordpress Search Function: Search Categories and Child Categories</title>
		<link>http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/</link>
		<comments>http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 06:23:56 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[WordPress as CMS]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[child category]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[parent category]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[subcategory]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/</guid>
		<description><![CDATA[<p class="dropcap-first">Recently, we had a client who wanted a special recipe search. There were 2 ways to extend the search functionality &#8211; manually or dynamically.</p>
<p>1. Search One or More Categories Manually
</p>
<p>If we want to search one category, we could have used this solution which lets you manually add category numbers ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Recently, we had a client who wanted a special recipe search. There were 2 ways to extend the search functionality &#8211; manually or dynamically.</p>
<p><strong>1. Search One or More Categories Manually<br />
</strong></p>
<p>If we want to search <strong>one category</strong>, we could have used this <a href="http://www.sandboxdev.com/blog/wordpress/123/search-specific-category-in-wordpress/">solution</a> which lets you manually add category numbers to the search function:</p>
<p>[Replace value="5" with your category number.]</p>
<blockquote><p>&lt;form method=&#8221;get&#8221; id=&#8221;searchform&#8221; action=&#8221;&lt;?php bloginfo(&#8216;home&#8217;); ?&gt;/&#8221;&gt;<br />
&lt;div&gt;<br />
&lt;input type=&#8221;text&#8221; value=&#8221;&lt;?php echo wp_specialchars($s, 1); ?&gt;&#8221; name=&#8221;s&#8221; id=&#8221;s&#8221; /&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;cat&#8221; value=&#8221;5&#8243; /&gt;<br />
&lt;input type=&#8221;submit&#8221; id=&#8221;searchsubmit&#8221; value=&#8221;Search&#8221; /&gt;<br />
&lt;/div&gt;<br />
&lt;/form&gt;</p></blockquote>
<p><strong>2. Search Subcategories Dynamically</strong></p>
<p>However, we wanted to dynamically search <strong>only the subcategories</strong> of the Recipe Category. The reason being that if you&#8217;re already in the Recipes section of the site, seeing a recipe labeled as Recipes is not helpful. However, seeing a recipe labeled as Dessert (mmm..) and Breakfast is helpful. So, each recipe that the client adds will be in a <strong>subcategory </strong>of recipes (ex. Dessert), but they won&#8217;t have to check off the checkbox next to the Recipes category itself.</p>
<p>Anyway, I&#8217;ve been looking for this solution for a long time and now, thanks to <a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fbitsofink.com%2F&amp;ei=YQtjSuS9MYaEmgOgvdT4Dw&amp;usg=AFQjCNG1logmg3Pto6eFPjwQ6fHtpve3Nw">Ilan Cohen</a>, I present it to you.</p>
<p>[Replace the number 5 with the parent category.]</p>
<blockquote><p>&lt;form method=&#8221;get&#8221; id=&#8221;searchform&#8221; action=&#8221;&lt;?php bloginfo(&#8216;home&#8217;); ?&gt;/&#8221;&gt;<br />
&lt;div id=&#8221;search&#8221;&gt;<br />
&lt;input type=&#8221;text&#8221; value=&#8221;Search&#8230; &#8221; onclick=&#8221;this.value=&#8221;;&#8221; name=&#8221;s&#8221; id=&#8221;s&#8221; /&gt;<br />
&lt;?php $categories = get_categories(&#8216;child_of=5&#8242;);<br />
$catlist = &#8221;;<br />
foreach ($categories as $cat) {<br />
$catlist.= $cat-&gt;cat_ID.&#8217;,';<br />
}<br />
$catlist.&#8217;5&#8242;;<br />
?&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;cat&#8221; value=&#8221;&lt;?php echo &#8220;$catlist&#8221;?&gt;&#8221; /&gt;<br />
&lt;input name=&#8221;" type=&#8221;image&#8221; src=&#8221;&lt;?php bloginfo(&#8217;stylesheet_directory&#8217;); ?&gt;/styles/&lt;?php echo &#8220;$style_path&#8221;; ?&gt;/search.gif&#8221; value=&#8221;Go&#8221; class=&#8221;btn&#8221; /&gt;<br />
&lt;/div&gt;&lt;!&#8211;/search &#8211;&gt;<br />
&lt;/form&gt;</p></blockquote>
<p>The code searches through all the child categories of Category 5 (Recipes). Then, you&#8217;ll see we added an additional &#8220;5&#8243; in this line: $catlist.&#8217;5&#8242;; just in case the client puts a recipe in the Recipes category, and not one of its subcategories.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-hack-the-wordpress-search-function-search-categories-and-child-categories%2F&amp;title=How+to+Hack+the+Wordpress+Search+Function%3A+Search+Categories+and+Child+Categories" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/how-to-hack-the-wordpress-search-function-search-categories-and-child-categories/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to create a Simple Directory in Wordpress using Grandparent, Parent, and Child Pages</title>
		<link>http://wpgarage.com/code-snippets/how-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages/</link>
		<comments>http://wpgarage.com/code-snippets/how-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 10:04:13 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[grandparent]]></category>
		<category><![CDATA[Pages]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/?p=464</guid>
		<description><![CDATA[<p class="dropcap-first">I wanted to create a simple directory of non-profit organizations. To do so,   I wanted to use pages for the directory, rather than posts so that I could separate the static directory listings from the dynamic blog posts. I didn&#8217;t want to have to exclude tons of categories ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">I wanted to create a simple directory of non-profit organizations. To do so,   I wanted to use pages for the directory, rather than posts so that I could separate the static directory listings from the dynamic blog posts. I didn&#8217;t want to have to exclude tons of categories from feedburner and the main loop.</p>
<p>So, I started exploring the whole family in Wordpress &#8211; grandparents, parents, and children. Translation for those not yet used to seeing Wordpress analagous to the family in My Big Fat Greek Wedding: Pages, sub-pages, and sub-sub pages</p>
<p><strong>Simple Directory Setup<br />
</strong></p>
<ul>
<li>Directory Page (grandparent): Displays list of Non-Profit Organization Categories  (ex. social, environment, health, etc.)</li>
<li>Category Page (parent): Show title and excerpt of each Organization within a category (ex. Environment Organizations)</li>
<li>Single Organization Page (child/current): Show content about a single organization(ex.  SaveTheEarth &#8211; made up org for this example)</li>
</ul>
<p><strong>Here&#8217;s how to do it</strong></p>
<ol>
<li>Create a Page Called Directory. This will be the <strong>Directory Page</strong> (grandparent)</li>
<li>Find the Page ID. Let&#8217;s say the Page ID = 5. Depending on how you want to display the category info, you can</li>
<li> Manually add the name of each category, a short description and a link</li>
<li>Open up page.php so we can setup <strong>The Category Page</strong> (Parent Page). We want to show title and excerpts of each organization for each category.</li>
<li>Add this code to page.php &#8211; Checks if we&#8217;re on a sub page / child page of the Directory (Page ID =10) and if so, list the pages in alphabetical order with excerpts. For the excerpt, I&#8217;m using the plugin Limit Posts since it didn&#8217;t work with The Excerpt Reloaded.&lt;?php<br />
$current = $post-&gt;ID;<br />
$parent = $post-&gt;post_parent;<br />
$grandparent_get = get_post($parent);<br />
$grandparent = $grandparent_get-&gt;post_parent;<br />
?&gt;</p>
<p>&lt;?php if ( $post-&gt;post_parent==&#8221;10&#8243;   ){ ?&gt;<br />
&lt;?php $pageChildren = $wpdb-&gt;get_results(&#8220;SELECT *    FROM $wpdb-&gt;posts WHERE post_parent = &#8220;.$post-&gt;ID.&#8221;    AND post_type = &#8216;page&#8217; ORDER BY post_title ASC&#8221;, &#8216;OBJECT&#8217;);    ?&gt;</p>
<p>&lt;h2 class=&#8221;titles&#8221;&gt;&lt;a href=&#8221;&lt;? php echo get_permalink($pageChild-&gt;ID);  ?&gt;&#8221;&gt; &lt;? php echo $pageChild-&gt;post_title;  ?&gt;&lt;/a&gt;&lt;/h2&gt;</p>
<p>&lt;?php the_content_limit(280, &#8220;&#8221;); ?&gt;&lt;div class=&#8221;readmore&#8221;&gt;&lt;a href=&#8221;&lt;?php echo get_permalink($pageChild-&gt;ID); ?&gt;&#8221; rel=&#8221;bookmark&#8221; title=&#8221;Permanent Link to &lt;? php echo $pageChild-&gt;post_title;   ?&gt;&#8221;&gt;Read More &amp;raquo;&lt;/a&gt;&lt;/div&gt;</p>
<p>(make sure to delete the space between &lt;? and php -  I had to to do that so it wouldn&#8217;t execute in this post)</li>
<li><strong>Single Organization Page </strong>(Child Page) On page.php, after the code you added in step 5, add this code that will check to see if we&#8217;re on the grandchild page. This will be the actual organization&#8217;s page. In our example, the SaveTheEarth Page. This is very helpful information in case you want to add a different style or add special items in the sidebar, etc.<br />
&lt;?php if ( $pageChildren ) : foreach ( $pageChildren as $pageChild ) : setup_postdata( $pageChild ); ?&gt;</li>
</ol>
<p style="padding-left: 30px;">7. Set up how the rest of the pages on your site will look:</p>
<p style="padding-left: 30px;">On page.php, after the code in step 6, add this code which instructs every other page in the site to act normally and display the content</p>
<p style="padding-left: 30px;">&lt;?php endforeach; ?&gt;<br />
&lt;?php else : ?&gt;</p>
<p style="padding-left: 30px;">&lt;?php the_content(); ?&gt;<br />
&lt;?php  endif; ?&gt;</p>
<p style="padding-left: 30px;">
<p><strong>You can see the full page.php code <a href="http://wpgarage.com/wp-content/uploads/2009/06/page.txt">here</a></strong></p>
<p><strong>You can see the directory in action <a href="http://israelnonprofitnews.com/directory/">here</a><br />
</strong></p>
<p>I figured this out using the following helpful posts:</p>
<p>*<a href="http://wordpress.org/support/topic/186206"> http://wordpress.org/support/topic/186206</a><br />
* <a href="http://wpguru.co.za/page/display-title-excerpt-of-child-page">http://wpguru.co.za/page/display-title-excerpt-of-child-page</a></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fhow-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages%2F&amp;title=How+to+create+a+Simple+Directory+in+Wordpress+using+Grandparent%2C+Parent%2C+and+Child+Pages" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/how-to-create-a-simple-directory-in-wordpress-using-grandparent-parent-and-child-pages/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to rename widgetized sidebars in Wordpress</title>
		<link>http://wpgarage.com/code-snippets/rename-widgetized-sidebars-in-wordpress/</link>
		<comments>http://wpgarage.com/code-snippets/rename-widgetized-sidebars-in-wordpress/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 11:01:08 +0000</pubDate>
		<dc:creator>Rebecca Markowitz</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[WordPress as CMS]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[widgetized sidebar]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/rename-widgetized-sidebars-in-wordpress/</guid>
		<description><![CDATA[<p class="dropcap-first">You can manage multiple sidebar widgets in WordPress. To do so, you go to the Widgets page in the Admin, and select the Sidebar you want to manage. If you have 1 widgetized sidebar, the name &#8220;Sidebar 1&#8243;  is not a big deal for managing it. But what ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">You can manage multiple sidebar widgets in WordPress. To do so, you go to the Widgets page in the Admin, and select the Sidebar you want to manage. If you have 1 widgetized sidebar, the name &#8220;Sidebar 1&#8243;  is not a big deal for managing it. But what if you have 5 or more, and they&#8217;re named Sidebar 1, Sidebar 2, etc. Ah yes, now what was  that wily sidebar 3 for?</p>
<p>Why would someone have so many sidebars to begin with? Well, remember that you can also add <a href="http://www.sueblimely.com/add-widget-ready-sidebars-to-wordpress-footers/">widget-ready sidebars to Wordpress footers</a> or anywhere in your design, to give extra content management options to clients.</p>
<p>Recently, we had a client with way too many widgetized sidebars to  keep track of, so we had to find a new solution to change the standard widget sidebar names like &#8220;sidebar 1&#8243; or &#8220;sidebar 2&#8243; to something  more meaningful like &#8220;Left sidebar&#8221; and &#8220;Right sidebar&#8221; in the admin  area. I dug around the web and found 2 very helpful posts:</p>
<ul>
<li><a href="http://www.blogherald.com/2007/05/24/how-to-use-widgets-with-more-than-one-sidebar-on-your-wordpress-blog/">How to use widgets with more than one sidebar on your WordPress blog</a></li>
<li><a href="http://internetducttape.com/2007/04/09/howto-design-a-variable-sidebar-wordpress-theme-with-widgets/">How to design a variable sidebar WordPress theme with widgets (by guest blogger Daria Black)</a></li>
</ul>
<p>Here&#8217;s what I learned:</p>
<p>1. Go into your themes&#8217;s <strong>function.php </strong>file, or if it doesn&#8217;t exist, create it.</p>
<p>Add the following code:</p>
<blockquote><p><strong>&lt;?php</strong></p>
<p><strong> if (function_exists(&#8216;register_sidebar&#8217;))</strong></p>
<p><strong>{</strong></p>
<p><strong>register_sidebar(array(</strong></p>
<p><strong>&#8216;before_widget&#8217; =&gt; &#8216;&lt;li&gt;&#8217;,</strong></p>
<p><strong>&#8216;after_widget&#8217; =&gt; &#8216;&lt;/li&gt;&#8217;,</strong></p>
<p><strong>&#8216;before_title&#8217; =&gt; &#8216;&lt;h4&gt;&#8217;,</strong></p>
<p><strong>&#8216;after_title&#8217; =&gt; &#8216;&lt;/h4&gt;&#8217;,</strong></p>
<p><strong></strong><strong>&#8216;name&#8217; =&gt; &#8216;Left sidebar&#8217;</strong></p>
<p><strong>));</strong></p>
<p><strong>register_sidebar(array(</strong></p>
<p><strong>&#8216;before_widget&#8217; =&gt; &#8216;&lt;li&gt;&#8217;,</strong></p>
<p><strong>&#8216;after_widget&#8217; =&gt; &#8216;&lt;/li&gt;&#8217;,</strong></p>
<p><strong>&#8216;before_title&#8217; =&gt; &#8216;&lt;h4&gt;&#8217;,</strong></p>
<p><strong>&#8216;after_title&#8217; =&gt; &#8216;&lt;/h4&gt;&#8217;,</strong></p>
<p><strong>&#8216;name&#8217; =&gt; &#8216;Right sidebar&#8217;</strong></p>
<p><strong>));</strong></p>
<p><strong>}</strong></p>
<p><strong>?&gt;</strong></p></blockquote>
<p>2a. Add a widgetized sidebar to your theme. Open up your theme&#8217;s sidebar file (for exampe, l_sidebar.php) and look for the first &lt;ul&gt; or &lt;ul id=&#8221;sidebar&#8221;&gt; or something similar, and add the following code:</p>
<blockquote><p><strong>&lt;?php if ( !function_exists(&#8216;dynamic_sidebar&#8217;) || !dynamic_sidebar(&#8216;Left sidebar&#8217;) ) : ?&gt;</strong></p></blockquote>
<p>2b. If your sidebar is already widgetized, find the following code</p>
<blockquote>
<blockquote><p><strong>&lt;?php if ( function_exists(&#8216;dynamic_sidebar&#8217;) &amp;&amp; dynamic_sidebar(1) ) : else : ?&gt;</strong></p></blockquote>
<p>and replace it with</p>
<blockquote><p><strong>&lt;?php if ( !function_exists(&#8216;dynamic_sidebar&#8217;) || !dynamic_sidebar(&#8216;Left sidebar&#8217;) ) : ?&gt;</strong></p></blockquote>
</blockquote>
<p>Then, find the closing &lt;/ul&gt; at the very bottom of the file, and immediately before that, place</p>
<p><strong>&lt;?php endif; ?&gt;</strong></p>
<p>3. Now, if you go into your admin panel, under Design&gt;Widgets, you&#8217;ll see the new names like in the image below.</p>
<p><img class="alignnone size-full wp-image-381" title="widgets" src="http://wpgarage.com/wp-content/uploads/2008/11/widgets.png" alt="" width="312" height="165" /></p>
<p>Now you can easily manage your Widgets without trying to guess which one is which.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Frename-widgetized-sidebars-in-wordpress%2F&amp;title=How+to+rename+widgetized+sidebars+in+Wordpress" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/rename-widgetized-sidebars-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Publishing WordPress posts in two columns</title>
		<link>http://wpgarage.com/code-snippets/publishing-wordpress-posts-in-two-columns/</link>
		<comments>http://wpgarage.com/code-snippets/publishing-wordpress-posts-in-two-columns/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 10:37:06 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[posts]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/publishing-wordpress-posts-in-two-columns/</guid>
		<description><![CDATA[<p class="dropcap-first">We&#8217;re currently building a site on Adii&#8217;s Premium Gazette WordPress theme (this is an affiliate link). In my opinion, it&#8217;s an awesome theme particularly because of the design. However, we installed it on the client&#8217;s server of choice, and the posts on the homepage just wouldn&#8217;t update. We tested ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">We&#8217;re currently building a site on <a href="https://www.e-junkie.com/ecom/gb.php?ii=85148&amp;c=ib&amp;aff=16393&amp;ev=45d256fd22">Adii&#8217;s Premium Gazette WordPress theme</a> (this is an affiliate link). In my opinion, it&#8217;s an awesome theme particularly because of the design. However, we installed it on the client&#8217;s server of choice, and the posts on the homepage just wouldn&#8217;t update. We tested it out on different servers, as well as on the client&#8217;s server without any plugins or changes, and it worked on other servers but would not cooperate on the client&#8217;s server.</p>
<p>The home page of this WordPress theme has two columns of posts. This is a really handy layout, but we realized that the code being used to create this layout was causing all the problems. So we needed to find another solution.</p>
<p>cre8d design has a tutorial on <a href="http://www.cre8d-design.com/blog/2008/03/01/how-to-organize-posts-into-two-side-by-side-columns-in-wordpress/" title="How to organize posts into two side-by-side columns in Wordpress">how to organize posts into two side-by-side columns in WordPress</a>. It&#8217;s based on adding  a &#8220;switch&#8221; that tells WordPress if a post should appear in the first column or the second column. Basically, the code is saying the following:</p>
<p><em>Are we in the first column?<br />
Yes: Move to the second column.<br />
No: Move to the first column.</em></p>
<p>The code calls styles from your style sheet that tell the left column to float left, and the right column to float right.</p>
<p>cre8d&#8217;s <a href="http://www.cre8d-design.com/demo/" title="cre8d demo page for two column layout">demo page for this technique:</a></p>
<p><img src="http://wpgarage.com/wp-content/uploads/2008/03/posts-two-columns-wordpress.png" alt="Posts in two columns in WordPress" /></p>
<p>We also needed to exclude two categories from appearing on the homepage, so here&#8217;s a simplified version of the final code we used to replace Adii&#8217;s code in his default.php file:</p>
<pre>&lt;div class="box"&gt;&lt;?php query_posts('showposts=4'); ?&gt;&lt;?php $hol = 1; ?&gt;

&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

&lt;?php if (in_category('3')) continue; ?&gt;

&lt;?php if (in_category('4')) continue; ?&gt;

&lt;?php if ($hol == 1) echo "&lt;div class=\"row\"&gt;"; ?&gt;

&lt;div class="post hol&lt;?php echo $hol;?&gt;" id="post-&lt;?

php the_ID(); ?&gt;"&gt;

&lt;?php if ( get_post_meta($post-&gt;ID, 'thumb', true) )

{ ?&gt; &lt;!-- DISPLAYS THE IMAGE URL SPECIFIED

IN THE CUSTOM FIELD --&gt;

&lt;img src="&lt;?php echo get_post_meta($post-&gt;ID, "thumb",

$single = true); ?&gt;" alt="" /&gt;

&lt;?php } else { ?&gt; &lt;!-- DISPLAY THE DEFAULT IMAGE, IF CUSTOM

FIELD HAS NOT BEEN COMPLETED --&gt;

&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;

/images/no-img-thumb.jpg" alt="" /&gt;

&lt;?php } ?&gt;

&lt;h2&gt;&lt;a title="Permanent Link to &lt;?php the_title(); ?&gt;"

href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt;</pre>
<pre>&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;&lt;?php the_excerpt(); ?&gt;&lt;/p&gt;

&lt;?php if ($hol == 1) echo "&lt;/div&gt;";

(($hol==1) ? $hol=2 : $hol=1); ?&gt;

&lt;/div&gt;&lt;!--/post--&gt;

&lt;?php endwhile; ?&gt;

&lt;?php endif; ?&gt;</pre>
<p>The following styles need to be added to your style sheet so that the columns float left and right:</p>
<p><code>.row { clear: both; }<br />
.hol1 { width: 200px; float: left; padding: 0 10px; }<br />
.hol2 { width: 200px; float: right;  padding: 0 10px; }</code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fpublishing-wordpress-posts-in-two-columns%2F&amp;title=Publishing+WordPress+posts+in+two+columns" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/publishing-wordpress-posts-in-two-columns/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Faviconize your WordPress admin</title>
		<link>http://wpgarage.com/code-snippets/faviconize-your-wordpress-admin/</link>
		<comments>http://wpgarage.com/code-snippets/faviconize-your-wordpress-admin/#comments</comments>
		<pubDate>Sun, 06 Jan 2008 09:28:24 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[favicon]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/faviconize-your-wordpress-admin/</guid>
		<description><![CDATA[<p class="dropcap-first">The WordPress admin doesn&#8217;t have a favicon. That means that when you&#8217;re working with a bunch of tabs open, it&#8217;s hard to identify which one is for your WordPress admin. Well, Simply Basic has the solution &#8211; simply add one line to wp-admin/admin-header.php that calls the favicon of your ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">The WordPress admin doesn&#8217;t have a favicon. That means that when you&#8217;re working with a bunch of tabs open, it&#8217;s hard to identify which one is for your WordPress admin. Well, Simply Basic has the solution &#8211; <a href="http://simply-basic.com/posts/194149" title="Give WP-Admin a Custom Favicon">simply add one line to <em>wp-admin/admin-header.php</em> that calls the favicon of your choice</a>:</p>
<p><code>&lt;link rel="shortcut icon" href="&lt;?php bloginfo('url'); ?&gt;/favicon.ico" &gt;</code></p>
<p>The only drawback is that you have to remember to redo this change every time you upgrade. It might be helpful if there was a plugin that did this for you (hint, hint).</p>
<p><a href="http://simply-basic.com/posts/194149">Simply-Basic.com » Give WP-Admin a Custom Favicon</a></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Ffaviconize-your-wordpress-admin%2F&amp;title=Faviconize+your+WordPress+admin" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/faviconize-your-wordpress-admin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using PHP to alternate background colors for comments or posts in WordPress</title>
		<link>http://wpgarage.com/code-snippets/using-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress/</link>
		<comments>http://wpgarage.com/code-snippets/using-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 15:05:10 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[posts]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/using-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress/</guid>
		<description><![CDATA[<p class="dropcap-first">Some blogs have alternating background colors for their comments and posts, i.e. a green background for every even comment and post, and a grey background for every odd comment and post. How do they do that?</p>
<p>Alternating Comments Styles</p>
<p>To alternate comments, add the following code to your comments.php template file, ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Some blogs have alternating background colors for their comments and posts, i.e. a green background for every even comment and post, and a grey background for every odd comment and post. How do they do that?</p>
<p><strong>Alternating Comments Styles</strong></p>
<p>To alternate comments, add the following code to your comments.php template file, under where it says <code>&lt;?php if ( $comments ) : ?&gt;</code>:</p>
<p><code>&lt;ul&gt;<br />
&lt;?php $i = 0; ?&gt;<br />
&lt;?php foreach ($comments as $comment) : ?&gt;<br />
&lt;?php $i++; ?&gt;<br />
&lt;li id="comment-&lt;?php comment_ID() ?&gt;"&lt;?php if($i&amp;1) { echo 'class="odd"';} else {echo 'class="even"';} ?&gt;&gt;</code></p>
<p>Then, create a style called .even and a style called .odd in your style.css file. Give each style a different background color, like this (but change the colors to what you want):</p>
<p><code>.odd {<br />
background-color: #fcf9fc; }</code></p>
<p><code>.even {<br />
background-color: #616161; }</code></p>
<p>This information is from the following WordPress support topic:</p>
<p><a href="http://wordpress.org/support/topic/108400">How to alternate background colors of comments posted on blog?</a></p>
<p><strong>Alternating Post Styles</strong></p>
<p>Adam Brown has a <a href="http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-users/posts-that-have-alternating-colors/" title="How do I make my posts (or anything else) have alternating colors?">tutorial on his site for creating alternating styles for posts</a>. Basically, you do the following:</p>
<ol>
<li>Right before the loop begins, add the following code:<br />
<code>&lt;?php $odd_or_even = 'odd'; ?&gt;</code></li>
<li>Right after the loop, there will be a div. Let&#8217;s say it&#8217;s called class=&#8221;post&#8221;. Change it to<br />
<code>&lt;div class="post &lt;?php echo $odd_or_even; ?&gt;"&gt;</code>, and then add the following piece of code on the next line: <code>&lt;?php $odd_or_even = ('odd'==$odd_or_even) ? 'even' : 'odd'; ?&gt;</code></li>
<li>Now, create .odd and .even styles in your style.css.</li>
</ol>
<p>Adam&#8217;s site has another really useful <a href="http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-users/">PHP Tutorial for Wordpress Users</a>, which is good for those of us who aren&#8217;t going to become PHP gurus, but would like to know enough PHP to extend our WordPress sites.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fusing-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress%2F&amp;title=Using+PHP+to+alternate+background+colors+for+comments+or+posts+in+WordPress" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/using-php-to-alternate-background-colors-for-comments-or-posts-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Giving each comment its own link in WordPress</title>
		<link>http://wpgarage.com/code-snippets/giving-each-comment-its-own-link-in-wordpress/</link>
		<comments>http://wpgarage.com/code-snippets/giving-each-comment-its-own-link-in-wordpress/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 11:43:52 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[comments]]></category>

		<guid isPermaLink="false">http://wordpressgarage.com/code-snippets/giving-each-comment-its-own-link-in-wordpress/</guid>
		<description><![CDATA[<p class="dropcap-first">Being able to link to specific comments in your WordPress blog could be very handy. Good comments can really add a lot of value to a blog, and you or others may want to refer to specific comments in your posts by linking to them. In general, comments can ...]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Being able to link to specific comments in your WordPress blog could be very handy. Good comments can really add a lot of value to a blog, and you or others may want to refer to specific comments in your posts by linking to them. In general, comments can be linked to, but to figure out what the URL is for every comment is virtually impossible, unless&#8230;you set up your comments section of your blog so that every comment gets a link.</p>
<p>Here&#8217;s how you would create a link around the date and time of your comment:</p>
<p><code>&lt;p&gt;&lt;a href="#comment-&lt;?php comment_ID() ?&gt;" title=""&gt;&lt;?php comment_date('F jS, Y') ?&gt; at &lt;?php comment_time() ?&gt;&lt;/a&gt;&lt;/p&gt;</code></p>
<p>This piece of code should appear in your comments.php theme file where your comment code appears.</p>
<p>If you want an &#8220;Edit Comment&#8221; link to appear next to the comment for those who are logged in and have permissions to edit, you would add the following code:</p>
<p><code>&lt;p&gt;&lt;a href="#comment-&lt;?php comment_ID() ?&gt;" title=""&gt;&lt;?php comment_date('F jS, Y') ?&gt; at &lt;?php comment_time() ?&gt;&lt;/a&gt;&lt;?php edit_comment_link('Edit comment',' ~ ',''); ?&gt;&lt;/p&gt;</code></p>
<p>So there you have it boys and girls: now you can link to comments, and share the love with your commenters!</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwpgarage.com%2Fcode-snippets%2Fgiving-each-comment-its-own-link-in-wordpress%2F&amp;title=Giving+each+comment+its+own+link+in+WordPress" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/giving-each-comment-its-own-link-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
