ThemeShaper Forums » Thematic

[closed]

Conditional function for home page

(9 posts)
  • Started 4 years ago by philbenoit
  • Latest reply from dire
  • This topic is not resolved
  1. philbenoit
    Member

    I am trying to create a site with the follow changes.

    1) on the home page the header and nav div's is removed totally

    2) on the internal pages the nav is moved from below "branding" to within the "branding"

    I have managed to achieve number 2 with the following code

    function replace_thematic_menu_position() {
    // remove menu
    remove_action('thematic_header','thematic_access',9);
    // replace menu with new hook
    add_action('thematic_header','thematic_access',6);
    }
    add_action('init','replace_thematic_menu_position');

    I am at a loss as to how to ensure this is activated with number one as well. I have tried the following but without success

    //setup function
    function childtheme_header_move() {
    //start of if statement
    	if (is_home() & !is_paged()) {
    		remove_action('thematic_header','thematic_brandingopen',1);
    		remove_action('thematic_header','thematic_blogtitle',3);
    		remove_action('thematic_header','thematic_blogdescription',5);
    		remove_action('thematic_header','thematic_brandingclose',7);
    	   	remove_action('thematic_header','thematic_access',9);
    	 } else {
    	 	// remove menu
    		remove_action('thematic_header','thematic_access',9);
    		remove_action('thematic_footer','thematic_siteinfo',30);
    		// replace menu with new hook
    		add_action('thematic_header','thematic_access',6);
    		}
    	}
    add_action('thematic_belowheader','childtheme_header_move');

    Any ideas would be appreciated

    Phil

    Posted 4 years ago #
  2. Hi philbenoit,

    You need to hook into the WP plugin API at a time when the conditional tag can be used.

    instead of add_action('thematic_belowheader','childtheme_header_move');

    try: add_action('template_redirect','childtheme_header_move');

    -Gene

    Posted 4 years ago #
  3. philbenoit
    Member

    Hi Gene,

    Tried this but still no dice.

    The nav and branding still appear on the home page. Is there something else I might be missing. The above is the total code I have used inside functions.php in my child theme.

    Thanks in advance!
    Phil

    Posted 4 years ago #
  4. Here's the rub: init is needed to remove thematic's actions but template_redirect is the needed because it's the first point at which a conditional tag can actually be true. So bundle up the two alternatives into separate init hooked functions and call them inside the conditional function.

    function child_firstpage_home_mod() {
    	// remove all of thematic's header content
    	remove_action('thematic_header','thematic_brandingopen',1);
    	remove_action('thematic_header','thematic_blogtitle',3);
    	remove_action('thematic_header','thematic_blogdescription',5);
    	remove_action('thematic_header','thematic_brandingclose',7);
    	remove_action('thematic_header','thematic_access',9);
    
    	// hook all of it into init inside this function
    	add_action('init','child_firstpage_home_mod');
    }
    
    function child_interior_mod() {
    	 // remove nav from it's default location
    	remove_action('thematic_header','thematic_access',9);
    	// remove footer site info
    	remove_action('thematic_footer','thematic_siteinfo',30);
    	// replace nav inside branding
    	add_action('thematic_header','thematic_access',6);
    
    	// hook all of it into init inside this function
    	add_action('init','child_interior_mod');
    }
    
    function childtheme_structural_mods() {
    	if (is_home() & !is_paged()) {
    		child_firstpage_home_mod();
    	} else {
    		child_interior_mod();
    	}
    }
    add_action('template_redirect','childtheme_structural_mods');
    Posted 4 years ago #
  5. philbenoit
    Member

    Thanks so much for you time on this em hr. I added the code to functions.php in my child theme. The child_interior_mod function works at moving the nav but the removing all on the home page does not for some reason.

    is there another way of asking the if (is_home() & !is_paged()) { statement?

    Posted 4 years ago #
  6. I have tested the above and it works for me on the home page if not paged.

    Hmmm, I'm not sure how you have things set up. Maybe what you need is if (is_front_page())instead of if (is_home() & !is_paged())

    Sometimes it's helpful for me to include some temporary visual cues when working with conditional tags.

    function childtheme_structural_mods() {
    	if (is_front_page()) {
    		child_firstpage_home_mod();
    		echo "<code>is_front_page</code> has returned: TRUE";
    	} else {
    		child_interior_mod();
    		echo "<code>is_front_page</code> has returned: FALSE";
    	}
    }
    add_action('template_redirect','childtheme_structural_mods');
    Posted 4 years ago #
  7. I'm far from an expert, but I was just looking at conditional tags yesterday.

    http://codex.wordpress.org/Conditional_Tags

    If you are using a static page as your home page (which I am just guessing at) then you need to use if (is_front_page()) to test if it is the home page or not. if (is_home()) refers to the blog index. and if (is_paged()) doesn't test whether a page is a page, but rather whether something sprawls across multiple pages.

    does your 2nd block of code work if you change

    add_action('thematic_belowheader','childtheme_header_move');

    to

    add_action('init','childtheme_header_move');

    Again, I don't have a clue if that will work, but it struck me that calling your function at thematic_belowheader would be too late. The header that you are trying to remove would already be written. No? Oh and I do agree w/ em hr about echoing out some dummy text just to try to isolate what part of your code is/not working.

    I am now confused by this template_redirect. I guess I had better go learn that. Good luck!

    cheers.

    Posted 4 years ago #
  8. philbenoit
    Member

    Hi guys,

    IT WORKS!! I changed the if (is_home() & !is_paged()) to if (is_front_page()) and all is good. Thanks so much em hr. Do you have a coffee fund I can donate to?

    @heigathviking - I must also now learn the ways of the template_redirect. Thanks for your input

    Phil

    Posted 4 years ago #
  9. dire
    Member

    Wow, I was looking for this conditional/'init' fix for a LONG time now. I had a much simpler problem -- I wanted to remove the nav menu just for the front page (but show for all others).

    Thank you, all!

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.