Support » Plugin: Widget Logic » Problem with is_home() – not working

  • iwildeachit


    I have read through the forum trying to find a solution, but I can’t seem to find a fix for my problem.

    Using is_home() OR is_front_page() on my homepage is returning a blank sidebar.
    My sidebar.php code is:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>
    	<?php endif; ?>

    If I add a query reset before the if, the widgets display but the pagination is thrown off.

    My home.php is:

    <?php get_header(); ?>
    <?php $show_sidebar = (get_option('thestyle_sidebar_home') == 'on') ? true : false; ?>
    <div id="content" class="clearfix<?php if ($show_sidebar && get_option('thestyle_blog_style') == 'false') echo(' sidebar-fixedwidth'); ?>">
    	<div id="boxes" class="<?php if (!$show_sidebar) echo('fullwidth'); if (get_option('thestyle_blog_style') == 'on') echo(' blogstyle-entries'); ?>">
    	<?php get_template_part('includes/entry','home'); ?>
    	<div id="content-bottom-bg"></div>
    <?php get_footer(); ?>

    And the includes/entry.php code is long, but attached:

    	$i = 0;
    	$show_sidebar = (get_option('thestyle_sidebar') == 'on') ? true : false;
    	if ( is_home() ){
    		$show_sidebar = (get_option('thestyle_sidebar_home') == 'on') ? true : false;
    			'showposts' => (int) get_option('thestyle_homepage_posts'),
    			'paged' => $paged,
    			'category__in' => array(3, 4, 88, 13, 14, 15, 16)
    			//removed by Terry //'category__not_in' => (array) get_option('thestyle_exlcats_recent')
    	} ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<?php if (get_option('thestyle_blog_style') == 'false') { ?>
    		<?php $biglayout = ( (bool) get_post_meta($post->ID,'et_bigpost',true) ) ? true : false;
    			$thumb = '';
    			$width = $biglayout ? 466 : 222;
    			$height = 180;
    			$classtext = '';
    			$titletext = get_the_title();
    			$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
    			$thumb = $thumbnail["thumb"]; ?>
    		<div class="entry <?php if ($biglayout) echo('big'); else echo('small');?>">
    			<div class="thumbnail">
    				<a href="<?php the_permalink(); ?>">
    					<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
    					<span class="overlay"></span>
    				<div class="category"><?php the_category(); ?></div>
    			<!--	<span class="month"><?php the_time('M'); ?><span class="date"><?php the_time('d'); ?></span></span> -->
    			</div> <!-- end .thumbnail -->
    			<h2 class="title"><a href="<?php the_permalink(); ?>"><?php if ($biglayout) truncate_title(45); else truncate_title(18); ?></a></h2>
    			<?php if ( in_category(array(4,5,6,7,8,9,10,11,12)) ) { ?>
    			<p class="postinfo"><?php esc_html_e('Program Date: ','TheStyle'); ?><?php global $wp_query; $postid = $wp_query->post->ID; echo date('F jS', strtotime(get_post_meta($postid, 'scadenza-date',true))); ?></p>
    			<?php } else { ?>
    						<p class="postinfo"></p>
    				<?php } ?>
    			<div class="entry-content">
    				<div class="bottom-bg">
    					<div class="excerpt">
    						<p><?php if ($biglayout) truncate_post(650); else truncate_post(295); ?> </p>
    					</div><!-- end .excerpt -->
    				</div><!-- end .bottom-bg -->
    			</div><!-- end .entry-content -->
    		</div><!-- end .entry -->
    	<?php } else { ?>
    		<div class="post">
    			<div class="post-content clearfix">
    				<div class="post-text">
    					<h2 class="blog-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    					<?php if (get_option('thestyle_postinfo1') <> '') { ?>
    						<p class="post-meta">
    							<?php esc_html_e('Posted','TheStyle'); ?> <?php if (in_array('author', get_option('thestyle_postinfo1'))) { ?> <?php esc_html_e('by','TheStyle'); ?> <?php the_author_posts_link(); ?><?php }; ?><?php if (in_array('date', get_option('thestyle_postinfo1'))) { ?> <?php esc_html_e('on','TheStyle'); ?> <?php the_time(get_option('thestyle_date_format')) ?><?php }; ?><?php if (in_array('categories', get_option('thestyle_postinfo1'))) { ?> <?php esc_html_e('in','TheStyle'); ?> <?php the_category(', ') ?><?php }; ?><?php if (in_array('comments', get_option('thestyle_postinfo1'))) { ?> | <?php comments_popup_link(esc_html__('0 comments','TheStyle'), esc_html__('1 comment','TheStyle'), '% '.esc_html__('comments','TheStyle')); ?><?php }; ?>
    					<?php }; ?>
    					<div class="hr"></div>
    					<?php the_content(); ?>
    					<?php wp_link_pages(array('before' => '<p><strong>'.esc_html__('Pages','TheStyle').':</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    					<?php edit_post_link(esc_html__('Edit this page','TheStyle')); ?>
    				</div> <!-- .post-text -->
    				<div class="info-panel">
    					<?php get_template_part('includes/infopanel'); ?>
    				</div> <!-- end .info-panel -->
    			</div> <!-- .post-content -->
    		</div><!-- end .post -->
    	<?php } ?>
    	<?php $i++; ?>
    <?php endwhile; ?>
    		</div> <!-- #boxes -->
    		<?php if ($show_sidebar) get_sidebar(); ?>
    	</div> <!-- #content -->
    	<div id="controllers" class="clearfix">
    		<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    		get_template_part('includes/navigation'); ?>
    	</div> <!-- #controllers -->
    <?php else : ?>
    			<?php get_template_part('includes/no-results'); ?>
    		</div> <!-- #boxes -->
    	</div> <!-- #content -->
    <?php endif; if ( is_home() ) wp_reset_query(); ?>

    Does anyone see a way I can re-work my query reset to allow proper functioning on my homepage as well as all other pages? I use lots of widgets.

    I am testing this on a XAMPP setup for the time-being, so I cannot post a URL for viewing.

    Thanks for any help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • iwildeachit


    I found a solution. I had to perform a query reset before calling the dynamic sidebars.



    Everything seemed to be working correctly…
    Then, all of a sudden random widgets started appearing on the homepage.

    Could someone more knowledgeable than myself in PHP, please review my code and make sure I have my query_reset’s in the correct area?

    I would truly be grateful!



    I thought I added my solution, but apparently I didn’t.

    In my /includes/entry.php file, I added:

    <?php wp_reset_query(); if ($show_sidebar) get_sidebar(); ?>
    near the end of the file and removed the reset_query on the last line.

    This allowed me to use is_home() to display widgets on the homepage.

    Plugin Contributor alanft


    I’d be interested to know if you get the same result if you remove that wp_reset_query(); and tick the ‘Use wp_reset_query fix’ option at the foot of the widget admin page



    I have tried doing that.
    Unfortunately, I get the same result (no sidebar widgets on front page.)



    I was also able to get the randon widgets to disappear by adding && !is_home() to the widgets that appeared, but that just seems a bit hacky. I have a lot of widgets on my site, and a fair amount of customized logic.

    Thank you! I was having the same problem. I wish I knew why? I just could not get is_home to work with my posts page (which I’d moved to /blog). Adding wp_reset_query(); before the sidebar fixed it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problem with is_home() – not working’ is closed to new replies.