ThemeShaper Forums » Thematic

[closed]

if else not working for remove header action

(5 posts)
  • Started 3 years ago by red23
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. I have a Problem i want to make a speceal layout for all my video posts. i want to remove the header for that reason and load another css file.

    the strange thing is. the css loads just fine and i use the same function "check_if_videopost()" but it not works for the header remove. when i uncomment it then it works fine.

    am i doing something wrong or is this maybe not possible to do in the "init" action?
    please help

    i want to uncomment and the if and else in the remove_header() function i dont want to remove it from every my entire site.

    /**
    * Tests if any of a post's assigned categories are descendants of target categories
    *
    * @param int|array $cats The target categories. Integer ID or array of integer IDs
    * @param int|object $_post The post. Omit to test the current post in the Loop or main query
    * @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
    * @see get_term_by() You can get a category by name or slug, then pass ID to this function
    * @uses get_term_children() Passes $cats
    * @uses in_category() Passes $_post (can be empty)
    * @version 2.7
    * @link http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category
    */
    if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
    function post_is_in_descendant_category( $cats, $_post = null ) {
    foreach ( (array) $cats as $cat ) {
    // get_term_children() accepts integer ID only
    $descendants = get_term_children( (int) $cat, 'category' );
    if ( $descendants && in_category( $descendants, $_post ) )
    return true;
    }
    return false;
    }
    }

    // parent category id of all video post $parentcat_of_all_video_post = IN HERE;
    function check_if_videopost() {
    $parentcat = 73;
    if (is_single() && post_is_in_descendant_category($parentcat)):
    return true;
    else:
    return false;
    endif;
    }

    function remove_header() {
    //if (check_if_videopost()):
    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);
    //endif;
    }
    add_action('init', 'remove_header');

    // load css for single posts who have are in child categories of the carent category xyz
    // give videoparentcat id of your video parent category
    function childtheme_css() {
    if (check_if_videopost()): ?>
    <link rel="stylesheet" type="text/css" href="<?php echo
    bloginfo('stylesheet_directory') ?>/video.css" />
    <?php endif;
    }
    add_action('wp_head', 'childtheme_css');
    `

    Posted 3 years ago #
  2. please put code between two backticks. looks like you tried, but forgot the opening backtick.

    i'm gonna guess init is too early a hook. try template_redirect or something a bit later in the WP process.

    Posted 3 years ago #
  3. i used but it not seem to work does it only work for one liners? it worked in my other post. or maybe i mistyped it. i test it now.

    anyway it worked, thanks ;)

    not working
    function remove_header() {
    if (check_if_videopost()):
    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);
    endif;
    }

    working

    function remove_header() {
    	if (check_if_videopost()):
    		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);
    	endif;
    }
    add_action('template_redirect', 'remove_header');
    Posted 3 years ago #
  4. <code>something code with new lines</code> is not working propably or is it not intended to work like backticks?

    Posted 3 years ago #
  5. i never use the code html tag but backticks always work for me. if the different hook worked, can you mark this thread as resolved

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.