ThemeShaper Forums » Thematic

[closed]

Remove widgetized areas except from home page

(24 posts)
  • Started 12 years ago by chris_s
  • Latest reply from middlesister
  • This topic is not resolved
  1. I want to be able to remove the widgetized areas from all pages except the home page.

    I attempted it with this code but came up with the following errors.

    function remove_widget_areas($content) {
    	if(!is_front_page()) {
    	  unset($content['1st Subsidiary Aside']);
    	  unset($content['2nd Subsidiary Aside']);
    	  unset($content['3rd Subsidiary Aside']);
      return $content;
    	}
    }
    
    add_filter('thematic_widgetized_areas', 'remove_widget_areas');

    errors:

    Warning: asort() expects parameter 1 to be array, null given in /home1/brokeupc/public_html/dv/wp-content/themes/thematic/library/extensions/widgets-extensions.php on line 336

    Warning: Invalid argument supplied for foreach() in /home1/brokeupc/public_html/dv/wp-content/themes/thematic/library/extensions/widgets-extensions.php on line 325

    EDIT: I realize that what this code did was take them out of the admin. What I am trying to do is just have them echo only on the home page.

    Posted 12 years ago #
  2. if you want to turn off the sidebar you'd do:

    function kill_sidebar() {
      if (is_front_page()) {
        return TRUE;
      } else {
        return FALSE;
      }
    }
    add_action('thematic_sidebar', 'kill_sidebar');

    killing all the rest of the widgets is possible but more involved

    Posted 12 years ago #
  3. Sorry, I forgot to specify the subsidiary-aside widgets in the footer...

    Posted 12 years ago #
  4. anyone have any input on this one?

    Posted 12 years ago #
  5. middlesister
    Member

    How about a childtheme override?

    function childtheme_override_subsidiaries() {
    	if( is_front_page() ) {
    		widget_area_subsidiaries();
    	}
    }
    Posted 12 years ago #
  6. I guess I'm missing something. When I use that and apply the filter, it removes it from all pages, including the front page...

    Posted 12 years ago #
  7. middlesister
    Member

    You don't need to apply any filters when you use a childtheme_override. Thematic will see your function and use it instead of the original.

    Posted 12 years ago #
  8. Hmmm... I tested without the filter and still the same result. Not sure what the culprit is.

    Posted 12 years ago #
  9. Nevermind... wasn't using childtheme_override_widget_area_subsidiaries. Works like a charm now. Thanks. Now I'm more familiar with child theme overrides.

    EDIT: I lied. The widgets are back with that last change in code... I can't figure this out for the life of me.

    Posted 12 years ago #
  10. middlesister
    Member

    Weird. I tried it on a test install and it works for me. The name of the function is just like I wrote - childtheme_override_subsidiaries(). Place it straight in your functions.php and not inside another function. You don't need any add_action or add_filter for it to get used.

    This code will only add the subsidiaries widget on the front page and not to any other pages. You can also try with is_home() if your front page is your blog page.

    Posted 12 years ago #
  11. This is super annoying. I don't have my home page set. Front-page.php is the home. Not sure what to do now.

    Posted 12 years ago #
  12. middlesister
    Member

    You don't have your home page set? Is that even possible? :-)

    What does your wordpress settings say, a static page or the blog page?

    Posted 12 years ago #
  13. haha. I guess it's not. it is set to latest posts, but I thought front-page.php overrides that. I did try is_home() and still nothing. I feel like a dam amateur over here!!

    Posted 12 years ago #
  14. middlesister
    Member

    Yes, front-page.php will override that and get used.

    Are you by any chance using query_posts() in that template? It will change the global values of $wp_query so some conditionals will no longer be the same. Take a look at http://forums.themeshaper.com/topic/multiple-loops-demystified#post-21144, and make sure that the global values are restored. Otherwise, wordpress will no longer know that it is on the front page.

    Posted 12 years ago #
  15. No, not in that template, but I am in another one in my child theme root for a Nivo Slider. Here is the code for my front-page.php

    <?php
    /*
    
     Template Name: Front Page
    
     */
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    		<div id="container" class="dv-front">
    
    			<?php thematic_abovecontent(); ?>
    
    			<div id="content" class="dv-front">
    	          <?php /*
    				<div id="slider" class="<?php echo (is_home()) ? 'home' : 'normal'; ?>">
    					<?php
    				    $tmp = $wp_query;
    				    $wp_query = new WP_Query('posts_per_page=3&category_name=hero');
    				    if(have_posts()) : while(have_posts()) : the_post();
    				    ?>
    				    	<?php the_post_thumbnail('nivoFront'); ?>
    				    <?php
    				    endwhile; endif;
    					$wp_query = $tmp;
    				    ?>
    		*/ ?>
    				<?php /*?></div><!-- close #slider --><?php */?>
    
    	        <?php
    
    	        thematic_belowpost();
    
    	        // calling the comments template
    	        thematic_comments_template();
    
    	        // calling the widget area 'page-bottom'
    	        get_sidebar('page-bottom');
    
    	        ?>
    
    			</div><!-- #content -->
    
    			<?php thematic_belowcontent(); ?> 
    
    		</div><!-- #container -->
    	<div id="clear"></div>
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling footer.php
        get_footer();
    
    ?>

    The query I have there is commented out, and will be used for use later. I will have to reset that, since I haven't already in that code. But mayeb you can see something else in here that is causing the problem.

    Posted 12 years ago #
  16. middlesister
    Member

    Well I can't see anything from the top of my mind. I guess you can clearly see that the template is used on the front page. Have you tried putting anything else in another action hook, just to see if is_front_page() works at all? Something like

    function front_page_test() {
        if ( is_front_page() ) {
            echo 'bacon!';
        }
    }
    add_action('thematic_abovecontent' , 'front_page_test')

    Otherwise, maybe you could try is_page_template('front-page.php') for the conditional in the childtheme_override function...

    Posted 12 years ago #
  17. It definitely is front-page. I've used that to test. And still nothing even with the conditional statement. I.Am.Stumped.

    Posted 12 years ago #
  18. middlesister
    Member

    Hm. Does it work if we go the add/remove action route?

    function remove_subsidiaries() {
    	remove_action('thematic_footer', 'thematic_subsidiaries', 10);
    }
    add_action('init' , 'remove_subsidiaries' );
    
    function readding_subsidiaries() {
    	if( is_front_page() ) {
    		add_action('thematic_footer', 'thematic_subsidiaries', 10);
    	}
    }
    add_action('template_redirect' , 'readding_subsidiaries');
    Posted 12 years ago #
  19. That actually worked. I wonder why that is. Is there any other info you want from me to try and get to the bottom of this?

    Thanks for the patience and help!

    Posted 12 years ago #
  20. middlesister
    Member

    Phew finally! :-D

    I wonder too. From what I see, widget_area_subsidiaries() is actually an action hook to which all the subsidiaries gets attached. My last resort would have been to unhook them all in order and add them conditionally back again, but I'm glad this worked too. I guess the hook function could not be conditionally replaced with the childtheme_override, don't really understand why though.

    Posted 12 years ago #
  21. Last question, and this is for my personal knowledge, where did you come up with the order number for subsidiaries? I know we're supposed to use them with removing actions, but I never read anywhere in the docs about subsidiaries having an order.

    Posted 12 years ago #
  22. middlesister
    Member

    Digging deeeep in the souce code. ;)

    No, really, the actions and order of thematic_footer are in footer_extensions.php and the action hooks for subsidiaries can be found in sidebar-extensions.php. I did a folderwise search for "widget_area_subsidiaries()", and they all popped up in the results. There really are action hooks everywhere - thematic_before_first_sub(), thematic_between_firstsecond_sub(), thematic_between_secondthird_sub() etc.

    Not all actions have priorities, but the ones added to thematic_header and thematic_footer have for sure. This makes it easy to switch the order of the div's around if you want. I haven't read about it in the docs either, but now we know the widget_area_subsidiaries have priorities too.

    Posted 12 years ago #
  23. Thanks for the explanation. I've now been better edumacated on how Thematic works and what's really possible! :)

    EDIT: Oooh ooh. One more. What's the template_redirect for? Haven't seen that used before.

    Posted 12 years ago #
  24. middlesister
    Member

    Its just that the init action fires really really early in the process, and the conditionals have not been set yet. If you need them, you need to add your action somewhere later. I don't really know all the wordpress actions or their order, but I have seen template_redirect been recommended before when there was a need for conditionals to work. I guess that template_redirect is used somewhere around fetching the right template page, so the conditinals definitely need to be set by then.

    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.