<?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; recent posts</title>
	<atom:link href="http://wpgarage.com/tag/recent-posts/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpgarage.com</link>
	<description>wordpress tricks, hacks, and tips</description>
	<lastBuildDate>Wed, 16 Nov 2011 14:36:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<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">?p=592</guid>
		<description><![CDATA[<p>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. I realize that you can just style the sticky post using the sticky-related classes provided [...]</p><p>This post was originally published at <a href="http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/">Display sticky post and exclude it from recent posts list in WordPress</a> on <a href="http://wpgarage.com">WP Garage</a> - <a href="http://wpgarage.com">WP Garage - wordpress tricks, hacks, and tips</a>.</p>]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/" data-url="http://illum.in/mVbXEl" data-text="Display sticky post and exclude it from recent posts list in WordPress" data-count="vertical" data-via="wpgarage" data-related="wpgarage"><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/&amp;layout=box_count&amp;show_faces=true&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/"></g:plusone></div></div><p>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( &#8216;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, &#8216;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(&#8216;sticky_posts&#8217;) ;</p>
<p>$post_to_exclude[] = $sticky[0];</p>
<p>$args=array(<br />
&#8216;caller_get_posts&#8217;=&gt;1,<br />
&#8216;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>
<p>This post was originally published at <a href="http://wpgarage.com/code-snippets/display-sticky-post-and-exclude-it-from-recent-posts-list-in-wordpress/">Display sticky post and exclude it from recent posts list in WordPress</a> on <a href="http://wpgarage.com">WP Garage</a> - <a href="http://wpgarage.com">WP Garage - wordpress tricks, hacks, and tips</a>.</p>]]></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>6</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>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. The site in question is still in [...]</p><p>This post was originally published at <a href="http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/">How to list the 4 latest posts with only one post per author in WordPress</a> on <a href="http://wpgarage.com">WP Garage</a> - <a href="http://wpgarage.com">WP Garage - wordpress tricks, hacks, and tips</a>.</p>]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><a href="http://twitter.com/share" class="twitter-share-button" data-counturl="http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/" data-url="http://illum.in/pe07NY" data-text="How to list the 4 latest posts with only one post per author in WordPress" data-count="vertical" data-via="wpgarage" data-related="wpgarage"><!--Tweetter--></a></div><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/&amp;layout=box_count&amp;show_faces=true&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/"></g:plusone></div></div><p>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="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(&#8217;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>
<p>This post was originally published at <a href="http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/">How to list the 4 latest posts with only one post per author in WordPress</a> on <a href="http://wpgarage.com">WP Garage</a> - <a href="http://wpgarage.com">WP Garage - wordpress tricks, hacks, and tips</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://wpgarage.com/code-snippets/list-4-latest-posts-with-only-one-post-per-author/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

