<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Check for Widgets in Widget-Areas</title>
	<atom:link href="http://wpengineer.com/1873/check-for-widgets-in-widget-areas/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com/1873/check-for-widgets-in-widget-areas/</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Wed, 08 Feb 2012 19:48:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dameer</title>
		<link>http://wpengineer.com/1873/check-for-widgets-in-widget-areas/#comment-6424</link>
		<dc:creator>Dameer</dc:creator>
		<pubDate>Fri, 28 Jan 2011 07:22:12 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1873#comment-6424</guid>
		<description>Hi all!
I was looking for a way to dynamically add sidebar widgets without involving WP&#039;s default 
&quot;if ( !function_exists( &#039;dynamic_sidebar&#039; ) &#124;&#124; !dynamic_sidebar( &#039;Home Page&#039; ) )&quot;
However, it&#039;s not easy to find out current sidebar index. WordPress does index them as &quot;sidebar-1&quot;, &quot;sidebar-2&quot;, &quot;sidebar-3&quot;, etc. in spite of the fact they might be named with &quot;Home Page&quot;, &quot;Category Page&quot;, &quot;Footer Column Left&quot;, etc.
Otherwise spoken, you can&#039;t rely on &quot;is_active_sidebar()&quot; without knowing sidebar $index (it&#039;s a required argument!). So, prior to above code, I found the following to work fine as a current sidebar index detector:

&lt;code&gt;
$how_many_widgets_here = 0;
$which_widgets_here = array();
$widget_area_name = &#039;Home Page&#039;; // seek for number of widgets in this widget-ready area
$required_sidebar_id = &#039;&#039;; // widget-ready area name/index assigned by WordPress
$keyz = array_keys( $wp_registered_sidebars ); // get keys of all
foreach( $keyz as $k =&gt; $v ) { // iterate all
	$single_arr = $wp_registered_sidebars[ $v ];
	foreach( $single_arr as $kk =&gt; $vv ) { // next level
		if( $vv == $widget_area_name ) {
			$required_sidebar_id = $single_arr[ &#039;id&#039; ]; // get the match
		}
	}
}
if( $required_sidebar_id != &#039;&#039; ) { // if not blank
	$all_widgets = wp_get_sidebars_widgets();
	$which_widgets_here = $all_widgets[ $required_sidebar_id ];
	$how_many_widgets_here = count( $all_widgets[ $required_sidebar_id ] ); 
}
&lt;/code&gt;

Yeap, the above code contains much more than required in this case, my intention is to leave it there coz someone could find it useful - who knows. What you will probably need here is actually &quot;$required_sidebar_id&quot; value.
Now it&#039;s safe to continue with:

&lt;code&gt;
if( function_exists( &#039;is_active_sidebar&#039; ) &amp;&amp; is_active_sidebar( $required_sidebar_id ) ) {

		dynamic_sidebar( $required_sidebar_id );

}
&lt;/code&gt;

Hopefully it helps.</description>
		<content:encoded><![CDATA[<p>Hi all!<br />
I was looking for a way to dynamically add sidebar widgets without involving WP's default<br />
"if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'Home Page' ) )"<br />
However, it's not easy to find out current sidebar index. WordPress does index them as "sidebar-1", "sidebar-2", "sidebar-3", etc. in spite of the fact they might be named with "Home Page", "Category Page", "Footer Column Left", etc.<br />
Otherwise spoken, you can't rely on "is_active_sidebar()" without knowing sidebar $index (it's a required argument!). So, prior to above code, I found the following to work fine as a current sidebar index detector:</p>
<p><code><br />
$how_many_widgets_here = 0;<br />
$which_widgets_here = array();<br />
$widget_area_name = 'Home Page'; // seek for number of widgets in this widget-ready area<br />
$required_sidebar_id = ''; // widget-ready area name/index assigned by WordPress<br />
$keyz = array_keys( $wp_registered_sidebars ); // get keys of all<br />
foreach( $keyz as $k =&gt; $v ) { // iterate all<br />
	$single_arr = $wp_registered_sidebars[ $v ];<br />
	foreach( $single_arr as $kk =&gt; $vv ) { // next level<br />
		if( $vv == $widget_area_name ) {<br />
			$required_sidebar_id = $single_arr[ 'id' ]; // get the match<br />
		}<br />
	}<br />
}<br />
if( $required_sidebar_id != '' ) { // if not blank<br />
	$all_widgets = wp_get_sidebars_widgets();<br />
	$which_widgets_here = $all_widgets[ $required_sidebar_id ];<br />
	$how_many_widgets_here = count( $all_widgets[ $required_sidebar_id ] );<br />
}<br />
</code></p>
<p>Yeap, the above code contains much more than required in this case, my intention is to leave it there coz someone could find it useful - who knows. What you will probably need here is actually "$required_sidebar_id" value.<br />
Now it's safe to continue with:</p>
<p><code><br />
if( function_exists( 'is_active_sidebar' ) &amp;&amp; is_active_sidebar( $required_sidebar_id ) ) {</code></p>
<p>		dynamic_sidebar( $required_sidebar_id );</p>
<p>}<br />
</p>
<p>Hopefully it helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://wpengineer.com/1873/check-for-widgets-in-widget-areas/#comment-2948</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sun, 06 Dec 2009 20:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1873#comment-2948</guid>
		<description>@Justin: Thanks for the tipp!</description>
		<content:encoded><![CDATA[<p>@Justin: Thanks for the tipp!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Tadlock</title>
		<link>http://wpengineer.com/1873/check-for-widgets-in-widget-areas/#comment-2947</link>
		<dc:creator>Justin Tadlock</dc:creator>
		<pubDate>Sun, 06 Dec 2009 18:18:05 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1873#comment-2947</guid>
		<description>I&#039;ve always loved this snippet of code and have used it for quite some time.  But, an equivalent of this function was added in WordPress 2.8: &lt;code&gt;is_active_sidebar()&lt;/code&gt;.  So, there&#039;s no need for a custom function any longer.</description>
		<content:encoded><![CDATA[<p>I've always loved this snippet of code and have used it for quite some time.  But, an equivalent of this function was added in WordPress 2.8: <code>is_active_sidebar()</code>.  So, there's no need for a custom function any longer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: designfollow</title>
		<link>http://wpengineer.com/1873/check-for-widgets-in-widget-areas/#comment-2946</link>
		<dc:creator>designfollow</dc:creator>
		<pubDate>Sun, 06 Dec 2009 11:38:03 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1873#comment-2946</guid>
		<description>great, thank you.</description>
		<content:encoded><![CDATA[<p>great, thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://wpengineer.com/1873/check-for-widgets-in-widget-areas/#comment-2945</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sun, 06 Dec 2009 11:35:11 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1873#comment-2945</guid>
		<description>Hi,

thanks a lot for mentioning our code :)

This snippet was build to prevent a fully styled but empty widgetized area. 

Last month I spoke to Kaspars Dambis the creator of the Widget Context plugin and asked him, if he could support this method with his plugin. The same day about 3 hours later I got a first working copy of his plugin.

The latest version of his plugin supports the above mentioned code snippets.

Chris</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>thanks a lot for mentioning our code <img src='http://wpengineer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This snippet was build to prevent a fully styled but empty widgetized area. </p>
<p>Last month I spoke to Kaspars Dambis the creator of the Widget Context plugin and asked him, if he could support this method with his plugin. The same day about 3 hours later I got a first working copy of his plugin.</p>
<p>The latest version of his plugin supports the above mentioned code snippets.</p>
<p>Chris</p>
]]></content:encoded>
	</item>
</channel>
</rss>

