<?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; Widget</title> <atom:link href="http://wpengineer.com/tag/widget/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=1845</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>24th Door &#8211; The WPE Quit Smoking Widget</title><link>http://wpengineer.com/24th-door-the-wpe-quit-smoking-widget/</link> <comments>http://wpengineer.com/24th-door-the-wpe-quit-smoking-widget/#comments</comments> <pubDate>Thu, 24 Dec 2009 07:12:19 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress Plugins]]></category> <category><![CDATA[Advent Calendar]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[Widget API]]></category> <category><![CDATA[WordPress]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1918</guid> <description><![CDATA[For the last door in our Advent Calendar I had something special in mind. This year is coming to an end and I'm sure some of our readers want to quit smoking next year. To support their goal, I created a WP Engineer Quit Smoking Widget. Here a screenshot of all setting possibilities: And this [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://wpengineer.com/blog/wp-content/uploads/WordPress-Christmas-24.jpg" alt="" title="WordPress-Christmas-24" width="600" height="400" class="aligncenter size-full wp-image-1902" />For the last door in our Advent Calendar I had something special in mind. This year is coming to an end and I'm sure some of our readers want to quit smoking next year. To support their goal, I created a WP Engineer Quit Smoking Widget. <img
src='http://wpengineer.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><span
id="more-1918"></span><br
/> Here a screenshot of all setting possibilities:</p><p><img
src="http://wpengineer.com/blog/wp-content/uploads/quit-smoking-widget.png" alt="WP Engineer Quit Smoking Widget" title="WPengineer Quit Smoking Widget" width="510" height="432" class="aligncenter size-full wp-image-1919" /></p><p>And this is how it would look like on your blog:</p><p><img
src="http://wpengineer.com/blog/wp-content/uploads/widget-output.png" alt="WP Enigineer Quit Smoking Widget Output" title="WP Enigineer Quit Smoking Widget Output" width="290" height="97" class="aligncenter size-full wp-image-1920" /></p><p>Even though, this idea seemed to be easy to realize. It was a piece of work. I don't want you to be bored, so I'm not explaining the whole code, but I just want go in detail on some details, what I had to consider to make this Widget workable.</p><p>I check the date if it's valid ( 2009/02/30 doesn't exist). Then I had to avoid division by zero, if the Widget is active but doesn't include any values yet. For the correct formatting of the saved money depending on the language I used the WordPress function <strong>number_format_i18n</strong>:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$saved</span> <span style="color: #339933;">=</span> number_format_i18n<span style="color: #009900;">&#40;</span><span style="color: #000088;">$packs</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$price</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Unfortunately, there is no feature in WordPress, which displays the currencies correctly (but I guess, this is probably not necessary). Therefore, I added a field "Currency position" with the values "before" and "after", so that the currency will be displayed properly, depending on the country. The year field automatically displays the current year minus 5 years, so that the widget is also current in 100 years. <img
src='http://wpengineer.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br
/> The rest are fields for entering the text output before and after values.</p><h3>Installation</h3><p>Unzip file wpe_quit_smoking_widget.zip and copy it to wp-content/plugins/ , then activate it in your backend. After that the Widget will be available in your Widgets area.</p><p>Please Note: The Widget needs <strong>WordPress Version 2.8</strong> or higher, otherwise it won't be displayed.</p><h3>Download</h3><p>Download <a
href="http://wpengineer.com/?download=WP%20Engineer%20Quit%20Smoking%20Widget" class="liinternal">WPEngineer Quit Smoking Widget</a></p><p>Have fun with the Widget and good luck with your goal to stop smoking! The team of WP Engineer wish you all Happy Holidays!</p><p><img
src="http://wpengineer.com/blog/wp-content/uploads/merry-christmas-wpengineer.jpg" alt="" title="merry-christmas-wpengineer" width="368" height="280" class="aligncenter size-full wp-image-1935" /><br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/" rel="bookmark" title="Permanent Link: Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget" class="liinternal">Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget</a></li><li><a
href="http://wpengineer.com/check-for-widgets-in-widget-areas/" rel="bookmark" title="Permanent Link: Check for Widgets in Widget-Areas" class="liinternal">Check for Widgets in Widget-Areas</a></li><li><a
href="http://wpengineer.com/wordpress-28-widgets-options-page/" rel="bookmark" title="Permanent Link: WordPress 2.8 Widgets Options Page &#8211; First Screenshot!" class="liinternal">WordPress 2.8 Widgets Options Page &#8211; First Screenshot!</a></li><li><a
href="http://wpengineer.com/add-wordpress-dashboard-widgets/" rel="bookmark" title="Permanent Link: Add WordPress Dashboard Widgets" class="liinternal">Add WordPress Dashboard Widgets</a></li><li><a
href="http://wpengineer.com/deactivate-wordpress-default-widgets/" rel="bookmark" title="Permanent Link: Deactivate WordPress Default Widgets" class="liinternal">Deactivate WordPress Default Widgets</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/24th-door-the-wpe-quit-smoking-widget/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Check for Widgets in Widget-Areas</title><link>http://wpengineer.com/check-for-widgets-in-widget-areas/</link> <comments>http://wpengineer.com/check-for-widgets-in-widget-areas/#comments</comments> <pubDate>Sun, 06 Dec 2009 07:28:11 +0000</pubDate> <dc:creator>Frank</dc:creator> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[Advent Calendar]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Theme]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[WP]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1873</guid> <description><![CDATA[Welcome to our 6th door of our Advent Calendar. If you use widgets in your theme and this also accommodates a variety of hierarchies, you will quickly realize that it really only makes sense to output HTML for the widgets when the widget area is also used by the user. Ian Stewart, the developer of [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://wpengineer.com/blog/wp-content/uploads/WordPress-Christmas-06.jpg" alt="WordPress-Christmas-06" title="WordPress-Christmas-06" width="600" height="400" class="aligncenter size-full wp-image-1884" />Welcome to our 6th door of our Advent Calendar. <img
src='http://wpengineer.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>If you use widgets in your theme and this also accommodates a variety of hierarchies, you will quickly realize that it really only makes sense to output HTML for the widgets when the widget area is also used by the user.</p><p><span
id="more-1873"></span><br
/> <a
href="http://themeshaper.com/" class="liexternal">Ian Stewart</a>, the developer of the Theme-Framework <a
href="http://code.google.com/p/thematic/" class="liexternal">Thematic</a> found an elegant solution, but you can use it even without the framework.<br
/> You just need one function, which is similar to the <a
href="http://codex.wordpress.org/Conditional_Tags" class="liwp">Conditional Tags</a> of WordPress. Put this function in your <code>functions.php</code> of your theme.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> is_sidebar_active<span style="color: #009900;">&#40;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_registered_sidebars</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$widgetcolums</span> <span style="color: #339933;">=</span> wp_get_sidebars_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgetcolums</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>It uses the output of your widget area, if there is content.</p><p>A query could look like this in your template:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'is_sidebar_active'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> is_sidebar_active<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div id=&quot;sidebar&quot;&gt;
		&lt;ul&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/ul&gt;
	&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>The above example loads the content only, if the widget area with the ID <code>sidebar</code> has content, that means if widgets are used in this area.<br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/deactivate-wordpress-default-widgets/" rel="bookmark" title="Permanent Link: Deactivate WordPress Default Widgets" class="liinternal">Deactivate WordPress Default Widgets</a></li><li><a
href="http://wpengineer.com/wordpress-widget-areas-with-description/" rel="bookmark" title="Permanent Link: WordPress Widget-Areas with Description" class="liinternal">WordPress Widget-Areas with Description</a></li><li><a
href="http://wpengineer.com/wordpress-28-widgets-options-page/" rel="bookmark" title="Permanent Link: WordPress 2.8 Widgets Options Page &#8211; First Screenshot!" class="liinternal">WordPress 2.8 Widgets Options Page &#8211; First Screenshot!</a></li><li><a
href="http://wpengineer.com/add-wordpress-dashboard-widgets/" rel="bookmark" title="Permanent Link: Add WordPress Dashboard Widgets" class="liinternal">Add WordPress Dashboard Widgets</a></li><li><a
href="http://wpengineer.com/wordpress-built-a-widget/" rel="bookmark" title="Permanent Link: Build A WordPress 2.8 Widget With The New Widget API" class="liinternal">Build A WordPress 2.8 Widget With The New Widget API</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/check-for-widgets-in-widget-areas/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget</title><link>http://wpengineer.com/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/</link> <comments>http://wpengineer.com/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/#comments</comments> <pubDate>Tue, 01 Dec 2009 04:43:41 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[Advent Calendar]]></category> <category><![CDATA[Theme]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[Widget API]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[WordPress Themes]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1875</guid> <description><![CDATA[Especially in Germany we have the tradition of an Advent Calendar. An Advent calendar is a special calendar which is used to count down the days from December the 1st to Christmas Eve December 24th. An Advent Calendar has 24 doors, one of which is opened every day during Advent. Each door opens to reveal [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://wpengineer.com/blog/wp-content/uploads/WordPress-Christmas-01.jpg" alt="WordPress-Christmas-01" title="WordPress-Christmas-01" width="600" height="400" class="aligncenter size-full wp-image-1879" /></p><p>Especially in Germany we have the tradition of an Advent Calendar. An Advent calendar is a special calendar which is used to count down the days from December the 1st to Christmas Eve December 24th.</p><p>An Advent Calendar has 24 doors, one of which is opened every day during Advent. Each door opens to reveal an image, a poem, or part of a story such as the Nativity story itself. More elaborate Advent calendars have a small gift concealed in each door, such as a toy or a chocolate item.</p><p>At WP Engineer, we thought we should do the same and open a door every day, which contains a little gift for our readers, by providing them a WordPress tip or trick each day. So we hope you will be exciting to see what tip, hack or news will be behind the door the next morning. Enjoy a new little WordPress gift every day until December 24th. <img
src='http://wpengineer.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Our first little gift is a code snippet to implement the commentform as a widget in your sidebar. This Widget only works with WordPress 2.8 and higher since it's using the new <a
href="http://wpengineer.com/wordpress-built-a-widget/" title="WordPress Widget API" class="liinternal">Widget API</a>. Just paste the code in the functions.php of your theme and drag the Widget on your sidebar.<br
/> <span
id="more-1875"></span></p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> wpe_comment_widget <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> wpe_comment_widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$widget_ops</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classname'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'wpe_widget_comments'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Your comments and commentform'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_textdomain'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WP_Widget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpe-comment-widget'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WPE Comments'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_textdomain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$widget_ops</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span><span style="color: #339933;">;</span>
            comments_template<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$old_instance</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This widget will only be displayed in single view.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_textdomain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
       <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
register_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpe_comment_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/new-ideas-for-2010-now-its-your-turn/" rel="bookmark" title="Permanent Link: New Ideas For 2010? Now It&#8217;s Your Turn!" class="liinternal">New Ideas For 2010? Now It&#8217;s Your Turn!</a></li><li><a
href="http://wpengineer.com/if-post-is-older-than/" rel="bookmark" title="Permanent Link: If Post is Older Than" class="liinternal">If Post is Older Than</a></li><li><a
href="http://wpengineer.com/configure-wordpress-trash/" rel="bookmark" title="Permanent Link: Configure WordPress Trash" class="liinternal">Configure WordPress Trash</a></li><li><a
href="http://wpengineer.com/check-for-widgets-in-widget-areas/" rel="bookmark" title="Permanent Link: Check for Widgets in Widget-Areas" class="liinternal">Check for Widgets in Widget-Areas</a></li><li><a
href="http://wpengineer.com/24th-door-the-wpe-quit-smoking-widget/" rel="bookmark" title="Permanent Link: 24th Door &#8211; The WPE Quit Smoking Widget" class="liinternal">24th Door &#8211; The WPE Quit Smoking Widget</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/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Deactivate WordPress Default Widgets</title><link>http://wpengineer.com/deactivate-wordpress-default-widgets/</link> <comments>http://wpengineer.com/deactivate-wordpress-default-widgets/#comments</comments> <pubDate>Wed, 02 Sep 2009 20:54:30 +0000</pubDate> <dc:creator>Frank</dc:creator> <category><![CDATA[WordPress Themes]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[development]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[WordPress Hacks]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1650</guid> <description><![CDATA[You do not always want to have all the widgets active, which comes within the WordPress core. You can disable the unneccessary Widgets in your functions.php of your theme with a small function. The following syntax will switch off all the standard widgets. It should therefore be adjusted depending on your requirements: // unregister all [...]]]></description> <content:encoded><![CDATA[<p>You do not always want to have all the widgets active, which comes within the WordPress core.</p><p>You can disable the unneccessary Widgets in your <code>functions.php</code> of your theme with a small function. The following syntax will switch off all the standard widgets. It should therefore be adjusted depending on your requirements:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// unregister all default WP Widgets</span>
<span style="color: #000000; font-weight: bold;">function</span> unregister_default_wp_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Calendar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Archives'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Links'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Meta'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Search'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Categories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Recent_Posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Recent_Comments'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_RSS'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	unregister_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget_Tag_Cloud'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widgets_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unregister_default_wp_widgets'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>The function <code>unregister_widget()</code> needs as parameters the class, therefore the code is working since version 2.8 only. In prior versions, Widgets were supported differently.</p><p>How to create your own Widgets since WordPress Version 2.8 is explained in <a
href="http://wpengineer.com/wordpress-built-a-widget/" class="liinternal">Build A WordPress 2.8 Widget With The New Widget API</a>.<br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/add-wordpress-dashboard-widgets/" rel="bookmark" title="Permanent Link: Add WordPress Dashboard Widgets" class="liinternal">Add WordPress Dashboard Widgets</a></li><li><a
href="http://wpengineer.com/check-for-widgets-in-widget-areas/" rel="bookmark" title="Permanent Link: Check for Widgets in Widget-Areas" class="liinternal">Check for Widgets in Widget-Areas</a></li><li><a
href="http://wpengineer.com/wordpress-28-widgets-options-page/" rel="bookmark" title="Permanent Link: WordPress 2.8 Widgets Options Page &#8211; First Screenshot!" class="liinternal">WordPress 2.8 Widgets Options Page &#8211; First Screenshot!</a></li><li><a
href="http://wpengineer.com/removing-wordpress-login-design/" rel="bookmark" title="Permanent Link: Removing WordPress Login Design" class="liinternal">Removing WordPress Login Design</a></li><li><a
href="http://wpengineer.com/wordpress-useful-default-configuration-settings-via-plugin/" rel="bookmark" title="Permanent Link: WordPress: Useful Default Configuration Settings Via Plugin" class="liinternal">WordPress: Useful Default Configuration Settings Via Plugin</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/deactivate-wordpress-default-widgets/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>WordPress 2.8 Single Post Navigation Widget</title><link>http://wpengineer.com/wordpress-2-8-single-post-navigation-widget/</link> <comments>http://wpengineer.com/wordpress-2-8-single-post-navigation-widget/#comments</comments> <pubDate>Mon, 27 Jul 2009 13:38:57 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[Widget API]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[wp2.8]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1551</guid> <description><![CDATA[Since WordPress 2.8, there is a new Widget API. In our post Build A WordPress 2.8 Widget With The New Widget API, I have used a simple example to describe how to build a Widget. This time Heiko and I've created something more complex. It is a Post Navigation Widget, which lists in the single [...]]]></description> <content:encoded><![CDATA[<p>Since WordPress 2.8, there is a new <strong>Widget API</strong>. In our post <a
href="http://wpengineer.com/wordpress-built-a-widget/" title="WordPress 2.8 Widget API" class="liinternal">Build A WordPress 2.8 Widget With The New Widget API</a>, I have used a simple example to describe how to build a <strong>Widget</strong>. This time Heiko and I've created something more complex.</p><p><span
id="more-1551"></span><br
/> It is a Post Navigation Widget, which lists in the single post view (single.php) a specific number of posts which were published before this post and a certain number of posts which were published after this post. I think this is a nice way to show older posts in the sidebar. Here's a screenshot, left of the backend, right of the sidebar:</p><p><img
src="http://wpengineer.com/blog/wp-content/uploads/post-navigation-widget.png" alt="WordPress Single Post Navigation Widget" title="WordPress Single Post Navigation Widget" width="505" height="386" class="aligncenter size-full wp-image-1553" /></p><p>I created a query to check if the class <strong>WP_Widget</strong> even exists, so the user won't get any error messages in WordPress versions prior to 2.8.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_Widget'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">class</span> WPE_Widget_Post_Navigation <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> WPE_Widget_Post_Navigation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$widget_ops</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classname'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'wpe_widget_post_navi'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Some posts before and after the current post&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WP_Widget</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpe-post-navi'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WPE Single Post Navigation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$widget_ops</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
                    <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$number</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
                    <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$number</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span>
                    <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000088;">$title_before</span> 		<span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget_title'</span><span style="color: #339933;">,</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'Posts before'</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$title_after</span>	 	<span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget_title'</span><span style="color: #339933;">,</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'Posts after'</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$before_widget_2</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/(wpe\-post\-navi-\d+)/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>-1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$before_widget</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000088;">$querystr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
                    SELECT *
                    FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> wposts
                    WHERE wposts.ID != <span style="color: #006699; font-weight: bold;">$post-&gt;ID</span>
                    AND wposts.post_type = 'post'
                    AND wposts.post_status = 'publish'
                    AND wposts.post_date <span style="color: #009933; font-weight: bold;">%s</span> '<span style="color: #006699; font-weight: bold;">$post-&gt;post_date</span>'
                    ORDER BY wposts.post_date <span style="color: #009933; font-weight: bold;">%s</span>
                    LIMIT <span style="color: #006699; font-weight: bold;">$number</span>
                 &quot;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000088;">$leading_posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$querystr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> OBJECT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$trailing_posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$querystr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ASC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> OBJECT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trailing_posts</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trailing_posts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget_2</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title_before</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$trailing_posts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_reverse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trailing_posts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trailing_posts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        setup_postdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;li&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> esc_attr<span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> ? get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/a&gt;&lt;/li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$leading_posts</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$leading_posts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title_after</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$leading_posts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        setup_postdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;li&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> esc_attr<span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> ? get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/a&gt;&lt;/li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$old_instance</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$new_instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$title_before</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'Posts before'</span> <span style="color: #339933;">:</span> esc_attr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$title_after</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'Posts after'</span> <span style="color: #339933;">:</span> esc_attr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$number</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$number</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Title before:&lt;/label&gt;
            &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_before'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title_before</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/p&gt;
            &lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Title after:&lt;/label&gt;
            &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_after'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title_after</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/p&gt;
            &lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Number of posts to show before and after current post:&lt;/label&gt;
            &lt;input id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'number'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$number</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;3&quot; /&gt;&lt;br /&gt;
            &lt;small&gt;(at most 10)&lt;/small&gt;&lt;/p&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    register_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WPE_Widget_Post_Navigation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Most of this should be self-explanatory. Now to the function <strong>widget () </strong>, which does the actual work. Here we had to do a little trick, because the widget actually creates 2 widgets, and they would get the same ID. That wouldn't be valid, so the code adds a -1 to one of the widget elements:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$before_widget_2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/(wpe\-post\-navi-\d+)/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>-1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$before_widget</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>2 queries are getting executed. One for the posts before this post and one for the posts after this post. if posts are available they will show up on the sidebar.</p><p><a
href="http://wpengineer.com/?download=Single%20Post%20Navigation%20Widget" title="Download Widget" class="liinternal">Download Widget</a>.<br
/> Then unpack and copy the code into <strong>functions.php</strong>. Please note, the widget is for <strong>WordPress 2.8</strong>.<br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/wordpress-built-a-widget/" rel="bookmark" title="Permanent Link: Build A WordPress 2.8 Widget With The New Widget API" class="liinternal">Build A WordPress 2.8 Widget With The New Widget API</a></li><li><a
href="http://wpengineer.com/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/" rel="bookmark" title="Permanent Link: Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget" class="liinternal">Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget</a></li><li><a
href="http://wpengineer.com/add-wordpress-dashboard-widgets/" rel="bookmark" title="Permanent Link: Add WordPress Dashboard Widgets" class="liinternal">Add WordPress Dashboard Widgets</a></li><li><a
href="http://wpengineer.com/wordpress-28-widgets-options-page/" rel="bookmark" title="Permanent Link: WordPress 2.8 Widgets Options Page &#8211; First Screenshot!" class="liinternal">WordPress 2.8 Widgets Options Page &#8211; First Screenshot!</a></li><li><a
href="http://wpengineer.com/new-navi-design-in-wordpress-27/" rel="bookmark" title="Permanent Link: New Navi-Design in WordPress 2.7" class="liinternal">New Navi-Design in WordPress 2.7</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/wordpress-2-8-single-post-navigation-widget/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Recents Drafts All Authors</title><link>http://wpengineer.com/recents-drafts-all-authors/</link> <comments>http://wpengineer.com/recents-drafts-all-authors/#comments</comments> <pubDate>Fri, 26 Jun 2009 11:36:20 +0000</pubDate> <dc:creator>Frank</dc:creator> <category><![CDATA[WordPress Plugins]]></category> <category><![CDATA[Feed]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Plugin]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[WP]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1343</guid> <description><![CDATA[It's not uncommon that a blog runs by different authors, so it may be useful if you can have a quick look at the drafts of all authors. In our joint blog WP Engineer we created a feed, which keeps us up to date if a new draft of all authors were created. The work [...]]]></description> <content:encoded><![CDATA[<p>It's not uncommon that a blog runs by different authors, so it may be useful if you can have a quick look at the drafts of all authors. In our joint blog WP Engineer we created a feed, which keeps us up to date if a new draft of all authors were created.</p><p>The work of every author is different and the dashboard is the center of information. Therefore we have decided to supplement a widget in the Dashboard, which shows the last five drafts of all authors. I enhanced the existing Plugin <a
href="http://wpengineer.com/feed-for-drafts-plugin/" class="liinternal">Draft Feed</a>.</p><ul><li>It provides a feed of all drafts</li><li>And the last 5 drafts of all authors in the Dashboard.</li></ul><p><span
id="more-1343"></span><br
/> <img
src="http://wpengineer.com/blog/wp-content/uploads/recents_draft.png" alt="recents_draft" title="recents_draft" width="362" height="225" class="aligncenter size-full wp-image-1344" /></p><p>Everybody who needs something like this, can download this Plugin from my <a
href="http://bueltge.de/wordpress-feed-fuer-entwuerfe/829/" class="liexternal">German Blog</a>. It doesn't have any options and doesn't exist in SVN of WordPress - if you want you can use and expand it or leave a comment if you have a question. Enjoy!<br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/wordpress-header/" rel="bookmark" title="Permanent Link: Cleanup WordPress Header" class="liinternal">Cleanup WordPress Header</a></li><li><a
href="http://wpengineer.com/feed-for-drafts-plugin/" rel="bookmark" title="Permanent Link: Feed for Drafts (Plugin)" class="liinternal">Feed for Drafts (Plugin)</a></li><li><a
href="http://wpengineer.com/new-ideas-for-2010-now-its-your-turn/" rel="bookmark" title="Permanent Link: New Ideas For 2010? Now It&#8217;s Your Turn!" class="liinternal">New Ideas For 2010? Now It&#8217;s Your Turn!</a></li><li><a
href="http://wpengineer.com/list-all-users-in-wordpress/" rel="bookmark" title="Permanent Link: List All Users in WordPress" class="liinternal">List All Users in WordPress</a></li><li><a
href="http://wpengineer.com/identify-authors-gravatars/" rel="bookmark" title="Permanent Link: Identify Authors With Gravatars" class="liinternal">Identify Authors With Gravatars</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/recents-drafts-all-authors/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>WordPress 2.8 Widgets Options Page &#8211; First Screenshot!</title><link>http://wpengineer.com/wordpress-28-widgets-options-page/</link> <comments>http://wpengineer.com/wordpress-28-widgets-options-page/#comments</comments> <pubDate>Mon, 13 Apr 2009 10:31:57 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress News]]></category> <category><![CDATA[backend]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[wp2.8]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1124</guid> <description><![CDATA[In the current trunk of WordPress is a "first run" of the new widget management available to see. This is a development version, it shows the warning "This page is not 100% ready, please use only on test installations.". Also new is that the sidebar now saves or updates via AJAX. Here is a Screenshot [...]]]></description> <content:encoded><![CDATA[<p>In the current trunk of WordPress is a "first run" of the new widget management available to see. This is a development version, it shows the warning "This page is not 100% ready, please use only on test installations.".<span
id="more-1124"></span></p><p>Also new is that the sidebar now saves or updates via AJAX. Here is a Screenshot from the current development version:</p><p><img
class="alignnone size-full" title="WordPress 2.8 Backend Widget Options" src="http://wpengineer.com/blog/wp-content/uploads/widgets.jpg" alt="WordPress 2.8 Backend Widget Options" width="590" height="365" /><br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/deactivate-wordpress-default-widgets/" rel="bookmark" title="Permanent Link: Deactivate WordPress Default Widgets" class="liinternal">Deactivate WordPress Default Widgets</a></li><li><a
href="http://wpengineer.com/add-wordpress-dashboard-widgets/" rel="bookmark" title="Permanent Link: Add WordPress Dashboard Widgets" class="liinternal">Add WordPress Dashboard Widgets</a></li><li><a
href="http://wpengineer.com/check-for-widgets-in-widget-areas/" rel="bookmark" title="Permanent Link: Check for Widgets in Widget-Areas" class="liinternal">Check for Widgets in Widget-Areas</a></li><li><a
href="http://wpengineer.com/quick-view-on-wordpress-settings/" rel="bookmark" title="Permanent Link: Quick View on WordPress Settings" class="liinternal">Quick View on WordPress Settings</a></li><li><a
href="http://wpengineer.com/meta-links-for-wordpress-plugins/" rel="bookmark" title="Permanent Link: Set Meta Links For WordPress Plugins" class="liinternal">Set Meta Links For WordPress Plugins</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/wordpress-28-widgets-options-page/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Build A WordPress 2.8 Widget With The New Widget API</title><link>http://wpengineer.com/wordpress-built-a-widget/</link> <comments>http://wpengineer.com/wordpress-built-a-widget/#comments</comments> <pubDate>Mon, 06 Apr 2009 11:00:45 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[Widget API]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[wp2.8]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=1023</guid> <description><![CDATA[One of the main changes in WordPress 2.8 is the new widget API. This API is fully object oriented and provides the programmer all the necessary functions to create a WordPress widgets. Also, it now allows multiple use of each widget. You can find the widget API in wp-includes/widget.php and the widgets itself in wp-includes/default-widgets.php. [...]]]></description> <content:encoded><![CDATA[<p>One of the main changes in WordPress 2.8 is the new <strong>widget API</strong>. This API is fully object oriented and provides the programmer all the necessary functions to create a WordPress widgets. Also, it now allows multiple use of each widget.</p><p><span
id="more-1023"></span></p><p>You can find the widget API in wp-includes/widget.php and the widgets itself in wp-includes/default-widgets.php. The class WP_Widget provides the functionality of the widgets, and each widget must be inherited. The class WP_Widget_Factory is for registration and instantiation of widgets responsible.</p><h3>How to create a widget in WordPress 2.8?</h3><p>It will be a simple example and will output the links for the RSS Feed of the articles and comments. In functions.php we first create the skeleton of our widgets:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> My_RSS_Widget <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> My_RSS_Widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Constructor</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// prints the widget</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//save the widget</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #000088;">$instance</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//widgetform in backend</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
register_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My_RSS_Widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>We have a class My_RSS_Widget created, which inherits the properties and methods of the WP_Widget class (extends). In a new widget, the methods <strong>widget</strong> and <strong>update</strong> always have to be created, <strong>form</strong> is optional. With <strong>register_widget</strong> ( 'My_RSS_Widget') will be the widget registered. Let's fill up our widget.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">class My_RSS_Widget extends WP_Widget {
	function My_RSS_Widget() {
		$widget_ops = array('classname' =&gt; 'widget_rss_links', 'description' =&gt; 'A list with your feeds links' );
		$this-&gt;WP_Widget('rss_links', 'Feed links', $widget_ops);
	}
&nbsp;
	function widget($args, $instance) {
		extract($args, EXTR_SKIP);
&nbsp;
		echo $before_widget;
		$title = empty($instance['title']) ? '&amp;nbsp;' : apply_filters('widget_title', $instance['title']);
		$entry_title = empty($instance['entry_title']) ? '&amp;nbsp;' : apply_filters('widget_entry_title', $instance['entry_title']);
		$comments_title = empty($instance['comments_title']) ? '&amp;nbsp;' : apply_filters('widget_comments_title', $instance['comments_title']);
&nbsp;
		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
		echo '&lt;ul id=&quot;rss&quot;&gt;';
		echo '  &lt;li&gt;&lt;a href=&quot; ' . get_bloginfo('rss2_url') . '&quot; rel=&quot;nofollow&quot; title=&quot; ' . $entry_title . ' &quot;&gt;' . $entry_title . '&lt;/a&gt;&lt;/li&gt;';
		echo '  &lt;li&gt;&lt;a href=&quot; ' . get_bloginfo('comments_rss2_url') . '&quot; rel=&quot;nofollow&quot; title=&quot;  '. $comments_title . ' &quot;&gt;' . $comments_title . '&lt;/a&gt;&lt;/li&gt;';
		echo '&lt;/ul&gt;';
		echo $after_widget;
	}
&nbsp;
	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['entry_title'] = strip_tags($new_instance['entry_title']);
		$instance['comments_title'] = strip_tags($new_instance['comments_title']);
&nbsp;
		return $instance;
	}
&nbsp;
	function form($instance) {
		$instance = wp_parse_args( (array) $instance, array( 'title' =&gt; '', 'entry_title' =&gt; '', 'comments_title' =&gt; '' ) );
		$title = strip_tags($instance['title']);
		$entry_title = strip_tags($instance['entry_title']);
		$comments_title = strip_tags($instance['comments_title']);
?&gt;
			&lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Title: &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> attribute_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/label&gt;&lt;/p&gt;
			&lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry_title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Title for entry feed: &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry_title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'entry_title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> attribute_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry_title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/label&gt;&lt;/p&gt;
			&lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comments_title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Title for comments feed: &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comments_title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comments_title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> attribute_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments_title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/label&gt;&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
register_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My_RSS_Widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p><img
src="http://wpengineer.com/blog/wp-content/uploads/rss-widget-backend.jpg" alt="RSS Widget Backend" title="RSS Widget Backend" width="286" height="321" class="aligncenter size-full wp-image-1025" /></p><p> The widget feature is for the output in the frontend to examine the update data and stores an instance of the widget and form creates in the backend the input mask, which in our case for the title of the widget and the displayed link text.</p><p>The code is self-explanatory. The function <strong>widget</strong> is for the output in the frontend responsible, <strong>update</strong> examine the data and stores an instance of the widget and <strong>form</strong> creates in the backend the input mask, which in our case for the title of the widget and the displayed link text.</p><p><img
src="http://wpengineer.com/blog/wp-content/uploads/rss-widget-frontend.jpg" alt="RSS Widget frontend" title="RSS Widget frontend" width="269" height="121" class="aligncenter size-full wp-image-1026" /></p><p>So now implement your own ideas!</p><p><strong>Please check out the post <a
href="http://wpengineer.com/wordpress-2-8-single-post-navigation-widget/" class="liinternal">WordPress 2.8 Single Post Navigation Widget</a> for a more advanced example.</strong><br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/deactivate-wordpress-default-widgets/" rel="bookmark" title="Permanent Link: Deactivate WordPress Default Widgets" class="liinternal">Deactivate WordPress Default Widgets</a></li><li><a
href="http://wpengineer.com/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/" rel="bookmark" title="Permanent Link: Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget" class="liinternal">Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget</a></li><li><a
href="http://wpengineer.com/wordpress-28-widgets-options-page/" rel="bookmark" title="Permanent Link: WordPress 2.8 Widgets Options Page &#8211; First Screenshot!" class="liinternal">WordPress 2.8 Widgets Options Page &#8211; First Screenshot!</a></li><li><a
href="http://wpengineer.com/wordpress-2-8-single-post-navigation-widget/" rel="bookmark" title="Permanent Link: WordPress 2.8 Single Post Navigation Widget" class="liinternal">WordPress 2.8 Single Post Navigation Widget</a></li><li><a
href="http://wpengineer.com/add-wordpress-dashboard-widgets/" rel="bookmark" title="Permanent Link: Add WordPress Dashboard Widgets" class="liinternal">Add WordPress Dashboard Widgets</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/wordpress-built-a-widget/feed/</wfw:commentRss> <slash:comments>47</slash:comments> </item> <item><title>WordPress and register_sidebar</title><link>http://wpengineer.com/wordpress-and-register_sidebar/</link> <comments>http://wpengineer.com/wordpress-and-register_sidebar/#comments</comments> <pubDate>Wed, 28 Jan 2009 16:14:20 +0000</pubDate> <dc:creator>Michael</dc:creator> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[Theme]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[WordPress]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=657</guid> <description><![CDATA[Everyone who is building WordPress Themes probably implement the widget function in their theme. Code for the widgets is in functions.php. Here a code snippet of the default theme: if &#40; function_exists&#40;'register_sidebar'&#41; &#41; register_sidebar&#40;array&#40; 'before_widget' =&#62; '&#60;li id=&#34;%1$s&#34; class=&#34;widget %2$s&#34;&#62;', 'after_widget' =&#62; '&#60;/li&#62;', 'before_title' =&#62; '&#60;h2 class=&#34;widgettitle&#34;&#62;', 'after_title' =&#62; '&#60;/h2&#62;', &#41;&#41;; As we all know, [...]]]></description> <content:encoded><![CDATA[<p>Everyone who is building WordPress Themes probably implement the widget function in their theme. Code for the widgets is in functions.php. Here a code snippet of the default theme:</p><p><span
id="more-657"></span></p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widgettitle&quot;&gt;'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p></p><p>As we all know, there is the function <strong>register_sidebar</strong> since version 2.2. My question is: <strong>How long do you want to ask if this function exists? </strong> The default theme of WordPress 2.7 doesn't ask, if <strong>have_comments</strong> (a new template tag of version 2.7) exists, but it asks if register_sidebar exists. I just suppose the developers just forgot it and everybody in the world thinks, that it has to be like that.</p><p>Please don't misunderstand, the query isn't wrong, but in my opinion just useless in the default theme of version 2.7</p><p>Since we are already talking about the register_sidebar and it's use, the code of a premium theme uses this query even 3 times:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Home Sidebar'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;block&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;&lt;div class=&quot;blockfooter&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Post Sidebar'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;block&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;&lt;div class=&quot;blockfooter&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Page Sidebar'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;block&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;&lt;div class=&quot;blockfooter&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h3&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>This is not really a good example for a premium theme. First, why closing the PHP tag after every function and open it before every function again?<br
/> Second, if the function register_sidebar exist in first place, it will also exist the 2nd time<br
/> and third, the code is almost identical except the name of the sidebar. That could be done much easier:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$sidebars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Home Sidebar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Post Sidebar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Page Sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sidebars</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$name</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;block&quot;&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;&lt;div class=&quot;blockfooter&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h3&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h3&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>As I said, it's not wrong and I didn't mean it as it is a bad way to code, but sometimes you can do it much easier <img
src='http://wpengineer.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/wordpress-widget-areas-with-description/" rel="bookmark" title="Permanent Link: WordPress Widget-Areas with Description" class="liinternal">WordPress Widget-Areas with Description</a></li><li><a
href="http://wpengineer.com/perfect-wordpress-theme/" rel="bookmark" title="Permanent Link: 10 Checks to the Perfect WordPress theme" class="liinternal">10 Checks to the Perfect WordPress theme</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/wordpress-and-register_sidebar/feed/</wfw:commentRss> <slash:comments>23</slash:comments> </item> <item><title>Add WordPress Dashboard Widgets</title><link>http://wpengineer.com/add-wordpress-dashboard-widgets/</link> <comments>http://wpengineer.com/add-wordpress-dashboard-widgets/#comments</comments> <pubDate>Mon, 27 Oct 2008 01:49:05 +0000</pubDate> <dc:creator>Frank</dc:creator> <category><![CDATA[WordPress Hacks]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Plugin]]></category> <category><![CDATA[Theme]]></category> <category><![CDATA[Widget]]></category> <category><![CDATA[WordPress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[WP]]></category> <category><![CDATA[wp2.7]]></category><guid
isPermaLink="false">http://wpengineer.com/?p=307</guid> <description><![CDATA[Finally WordPress 2.7 is coming along with widgets in the dashboard area, so it will be possible to adjust your dashboard as you like. For Plugin or theme authors it's even more interesting, since they can give the users additional value to their Plugins. They can offer information from their Plugin directly on the dashboard. [...]]]></description> <content:encoded><![CDATA[<p>Finally WordPress 2.7 is coming along with widgets in the dashboard area, so it will be possible to adjust your dashboard as you like.</p><p>For Plugin or theme authors it's even more interesting, since they can give the users additional value to their Plugins. They can offer information from their Plugin directly on the dashboard. The user can decide if he likes to display them or not.</p><p>It's easy to integrate and can be controlled like <a
href="http://wpengineer.com/use-metaboxes-in-your-theme-or-plugin/" class="liinternal">Meta Boxes (explained in detail)</a>. The following example shows how you can integrate a widget in a dashboard.<br
/> <span
id="more-307"></span></p> </pre><p><div
id="attachment_308" class="wp-caption aligncenter" style="width: 460px"><img
src="http://wpengineer.com/blog/wp-content/uploads/wp27-dashboard-erweitern.png" alt="WP 2.7 with new Widget in Dashboard" title="wp27-dashboard-expand" width="450" height="308" class="size-full wp-image-308" /><p
class="wp-caption-text">WP 2.7 with new Widget in Dashboard</p></div></p><p>The above screenshot shows that I addes the widget <em>Test My Dashboard</em>. Also you can see the possibility to deactivate the widget in the menu.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Content of Dashboard-Widget
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> my_wp_dashboard_test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Test Add Dashboard-Widget'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * add Dashboard Widget via function wp_add_dashboard_widget()
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> my_wp_dashboard_setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_add_dashboard_widget<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'my_wp_dashboard_test'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Test My Dashboard'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_wp_dashboard_test'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * use hook, to integrate new widget
 */</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_dashboard_setup'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_wp_dashboard_setup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>The function <code>wp_add_dashboard_widget()</code> is the key, which delivers the new widget; via hook <code>wp_dashboard_setup</code> it will be activated on the dashboard.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> wp_add_dashboard_widget<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$widget_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$widget_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$callback</span><span style="color: #339933;">,</span> <span style="color: #000088;">$control_callback</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span></pre></div></div><p>The function needs 3 parameters and an additional one is optional.</p><ol><li>The <strong>ID</strong>, <em>first parameter</em>,will be used to deactivate the widget via JavaScript. In the Menu:<div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>label <span style="color: #b1b100;">for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;my_wp_dashboard_test-hide&quot;</span><span style="color: #339933;">&gt;&lt;</span>input <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hide-postbox-tog&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;my_wp_dashboard_test-hide&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;my_wp_dashboard_test-hide&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;my_wp_dashboard_test&quot;</span> checked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checked&quot;</span> <span style="color: #339933;">/&gt;</span>Test My Dashboard<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span></pre></div></div><p>and also in the widget:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;my_wp_dashboard_test&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;postbox &quot;</span> <span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>h3 <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'hndle'</span><span style="color: #339933;">&gt;&lt;</span>span<span style="color: #339933;">&gt;</span>Test My Dashboard<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;&lt;/</span>h3<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;inside&quot;</span><span style="color: #339933;">&gt;</span>Test Add Dashboard<span style="color: #339933;">-</span>Widget<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div></li><li>The <em>second parameter</em> delivers the <strong>name</strong>, which will be displayed, wrapped in an h3-tag.<div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>h3 <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'hndle'</span><span style="color: #339933;">&gt;&lt;</span>span<span style="color: #339933;">&gt;</span>Test My Dashboard<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;&lt;/</span>h3<span style="color: #339933;">&gt;</span></pre></div></div></li><li>With the help of the <em>third parameter</em> the third <strong>function</strong> gets delivered, it contains the content of the widget. The <code>echo</code> does not take place, you have to use it explicitly. Therefore not only the content can be displayed, which makes it more flexible.</li></ol><h4>Hint</h4><p>The hook <code>activity_box_end</code>, which is available since version 2.3, still exists. It adds the content in widget &#8222;<em>Right Now</em>&#8220;.</p><h4>Update</h4><p>Nice to read: a update of this post to include options in the dashboard widget: <a
href="http://rick.jinlabs.com/2009/02/01/how-add-options-to-your-wordpress-27-dashboard-widgets/" class="liexternal">How add options to your WordPress 2.7 dashboard widgets</a><br
/><hr
/><h3>Related posts:</h3><ul><li><a
href="http://wpengineer.com/deactivate-wordpress-default-widgets/" rel="bookmark" title="Permanent Link: Deactivate WordPress Default Widgets" class="liinternal">Deactivate WordPress Default Widgets</a></li><li><a
href="http://wpengineer.com/new-navi-design-in-wordpress-27/" rel="bookmark" title="Permanent Link: New Navi-Design in WordPress 2.7" class="liinternal">New Navi-Design in WordPress 2.7</a></li><li><a
href="http://wpengineer.com/recents-drafts-all-authors/" rel="bookmark" title="Permanent Link: Recents Drafts All Authors" class="liinternal">Recents Drafts All Authors</a></li><li><a
href="http://wpengineer.com/wordpress-admin-ui-ideas/" rel="bookmark" title="Permanent Link: WordPress Admin UI Ideas" class="liinternal">WordPress Admin UI Ideas</a></li><li><a
href="http://wpengineer.com/check-for-widgets-in-widget-areas/" rel="bookmark" title="Permanent Link: Check for Widgets in Widget-Areas" class="liinternal">Check for Widgets in Widget-Areas</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/add-wordpress-dashboard-widgets/feed/</wfw:commentRss> <slash:comments>34</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 53/100 queries in 1.315 seconds using disk
Object Caching 2905/3074 objects using disk

Served from: wpengineer.com @ 2010-07-29 12:58:39 -->