<?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 Engineer &#187; conditional tag</title> <atom:link href="http://wpengineer.com/tag/conditional-tag/feed/" rel="self" type="application/rss+xml" /><link>http://wpengineer.com</link> <description>WordPress News, Hacks, Tipps, Tutorials, Plugins and Themes</description> <lastBuildDate>Wed, 28 Jul 2010 13:37:05 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=2883</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Strange Things With Sticky Posts</title><link>http://wpengineer.com/strange-things-with-sticky-posts/</link> <comments>http://wpengineer.com/strange-things-with-sticky-posts/#comments</comments> <pubDate>Wed, 22 Oct 2008 04:28:14 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[conditional tag]]></category> <category><![CDATA[sticky]]></category> <category><![CDATA[template tag]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[wp2.7]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=293</guid> <description><![CDATA[Frank wrote in one of his last posts about the new sticky functionality in WordPress 2.7. Right now I'm working on a special theme and I noticed some strange things with sticky posts. Wrong Post Count If you like to show 6 posts on a page, I use query_posts('showposts=6');. But if one or more posts [...]]]></description> <content:encoded><![CDATA[<p>Frank wrote in one of his last posts about the new <a
href="http://wpengineer.com/sticky-function-in-wordpress-27/" title="sticky function in WordPress 2.7" class="liinternal">sticky functionality</a> in WordPress 2.7. Right now I'm working on a special theme and I noticed some strange things with sticky posts.<br
/> <span
id="more-293"></span></p><h3>Wrong Post Count</h3><p>If you like to show 6 posts on a page, I use <code>query_posts('showposts=6');</code>. But if one or more posts are "sticky", they get added to the other 6 posts. To show 6 posts actually, you have to know how many sticky posts you have.</p><p><strong>The solution:</strong></p><p><code>get_option('sticky_post')</code> gives you an array back with sticky post ID, which we can count.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sticky</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sticky_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'showposts='</span><span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">6</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$sticky</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><h3>Still showing sticky posts in chronological sort order</h3><p>Pay attention to the CSS classes of the posts. The template tag <code>post_class()</code> gives the post the class. In the case of sticky post, it is also the class "sticky". If you think you can give the class sticky a red background and black border to have a nice teaser you will be disappointed. If you go to the next page to see previous posts, the sticky post will also be showed in the chronological order with a red background and black borders. Not really cool.</p><h3>Kill the Sticky</h3><p>If you don't want to have sticky posts, just write in your template:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sticky_posts'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>With the empty array you overwrite the sticky options and no sticky posts are availably.</p><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/sticky-function-in-wordpress-27/" rel="bookmark" title="Permanent Link: Sticky Function in WordPress 2.7" class="liinternal">Sticky Function in WordPress 2.7</a></li><li><a
href="http://wpengineer.com/correct-pagination-with-get_posts/" rel="bookmark" title="Permanent Link: Correct Pagination with get_posts" class="liinternal">Correct Pagination with get_posts</a></li><li><a
href="http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/" rel="bookmark" title="Permanent Link: The Ultimative Guide For the_post_thumbnail In WordPress 2.9" class="liinternal">The Ultimative Guide For the_post_thumbnail In WordPress 2.9</a></li><li><a
href="http://wpengineer.com/load-a-stylesheet-only-if-use-gallery/" rel="bookmark" title="Permanent Link: Load A Stylesheet Only If Use Gallery" class="liinternal">Load A Stylesheet Only If Use Gallery</a></li><li><a
href="http://wpengineer.com/related-posts-on-category/" rel="bookmark" title="Permanent Link: Related Posts on Category" class="liinternal">Related Posts on Category</a></li></ul><hr
/><p><img
style="float:left;" src="http://wpengineer.com/favicon.ico" alt="WP Engineer Favicon"/> Thanks for subscribing our feed! <a
href="http://buysellads.com/buy/detail/3646/" class="liexternal">Sponsor the WP Engineer Blog</a> and get your brand in front of several hundred users per day!<br
/> &copy; <a
href="http://wpengineer.com/" class="liinternal">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p> ]]></content:encoded> <wfw:commentRss>http://wpengineer.com/strange-things-with-sticky-posts/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Database Caching 24/34 queries in 0.062 seconds using disk
Object Caching 458/522 objects using disk

Served from: wpengineer.com @ 2010-07-29 13:29:00 -->