Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Inactive Widget Issue WordPress

  • SOLVED

I asked in another thread a question about placing a widget after every post in Genesis. However, proper standard for putting a widget in a theme in Genesis is to make sure that if the widget is not active , which is is_active_sidebar('nameofsidebar'), then the widget will not show up.

I need the following code to be fixed to make sure that it is correct and does not display any part of the widget if it is not being used (not active). The code below with the multiple sidebars is set up... but the code was still outputting part of the widget... if the widget was active, then there was a bottom border that showed up... BUT this still remains when the widget is not being used or is not active.


//* Adds a different widget after each post up to 10 if a site displays 10 posts to a page
add_action( 'genesis_after_entry', 'add_text_after_post_entry' );
function add_text_after_post_entry() {

//we can use for example an array of IDs widgets
$slh_widgets_ids = array('teaser-1','teaser-2','teaser-3','teaser-4','teaser-5','teaser-6','teaser-7','teaser-8','teaser-9','teaser-10');

global $post_count;
$post_count++;
$slh_widget_id = $slh_widgets_ids[$post_count-1];

if( $post_count < 11 || is_active_sidebar( 'teaser-1' ) || is_active_sidebar( 'teaser-2' ) || is_active_sidebar( 'teaser-3' ) || is_active_sidebar( 'teaser-4' ) || is_active_sidebar( 'teaser-5' ) || is_active_sidebar( 'teaser-6' ) || is_active_sidebar( 'teaser-7' ) || is_active_sidebar( 'teaser-8' ) || is_active_sidebar( 'teaser-9' ) || is_active_sidebar( 'teaser-10' ) && !is_singular() ) {

echo '<div class="'.$slh_widget_id.' widget-area"><div class="wrap"><center>';

dynamic_sidebar( $slh_widget_id );

echo '</center></div></div><!-- end .'.$slh_widget_id.' -->';
}
}


Screenshot of what I'm trying to talk about is attached

Answers (2)

2014-02-21

Bob answers:

you are checking that if any sidebar is active then go inside conidtion.
you should check if current sidebar that you are going to show is active or not?

//* Adds a different widget after each post up to 10 if a site displays 10 posts to a page
add_action( 'genesis_after_entry', 'add_text_after_post_entry' );
function add_text_after_post_entry() {
//we can use for example an array of IDs widgets
$slh_widgets_ids = array('teaser-1','teaser-2','teaser-3','teaser-4','teaser-5','teaser-6','teaser-7','teaser-8','teaser-9','teaser-10');
global $post_count;
$post_count++;
$slh_widget_id = $slh_widgets_ids[$post_count-1];
if( is_active_sidebar( $slh_widget_id ) && !is_singular() ) {

echo '<div class="'.$slh_widget_id.' widget-area"><div class="wrap"><center>';
dynamic_sidebar( $slh_widget_id );
echo '</center></div></div><!-- end .'.$slh_widget_id.' -->';
}
}


I am assuming that you have created 10 sidebars.


Bob comments:

we also do not require to check <em>$post_count < 11</em>.

only check if the sidebar you are going to show is active or not and the current page is not singular?


Nile Flores comments:

Awesome. Voting

2014-02-21

Navjot Singh answers:

Change

if( $post_count < 11 || is_active_sidebar( 'teaser-1' ) || is_active_sidebar( 'teaser-2' ) || is_active_sidebar( 'teaser-3' ) || is_active_sidebar( 'teaser-4' ) || is_active_sidebar( 'teaser-5' ) || is_active_sidebar( 'teaser-6' ) || is_active_sidebar( 'teaser-7' ) || is_active_sidebar( 'teaser-8' ) || is_active_sidebar( 'teaser-9' ) || is_active_sidebar( 'teaser-10' ) && !is_singular() )

to

if( ($post_count < 11) && (is_active_sidebar( 'teaser-1' ) || is_active_sidebar( 'teaser-2' ) || is_active_sidebar( 'teaser-3' ) || is_active_sidebar( 'teaser-4' ) || is_active_sidebar( 'teaser-5' ) || is_active_sidebar( 'teaser-6' ) || is_active_sidebar( 'teaser-7' ) || is_active_sidebar( 'teaser-8' ) || is_active_sidebar( 'teaser-9' ) || is_active_sidebar( 'teaser-10' ) && !is_singular()) )

Your code is fulfilling now even when the post count is less than 11 because widgets are optional with it. The condition that widget are present and the post count is less than 11 should both be satisfied simultaneously for this to happen.


Nile Flores comments:

The line is still showing up. I'm testing the first teaser on [[LINK href="http://webhost-solutions.net/diyp"]]http://webhost-solutions.net/diyp[[/LINK]] .