• Resolved charlesolaes

    (@charlesolaes)


    I have a template file called home.php. I’m using the thematic theme and the home.php is in the child theme folder.

    The thematic theme allows me to add content through action hooks… I made a widget area to be displayed only at the home page but when I use the conditional tag is_home(), it returns false but it returns TRUE for is_category() even though it’s being called in the home.php. Here’s my code

    //create the widget area
    $args2 = array(
    	'name'          => ('Below Content'),
    	'id'            => 'child-below-content',
    	'description'   => 'Widget area for content after index loop',
    	'before_widget' => thematic_before_widget(),
    	'after_widget'  => thematic_after_widget(),
    	'before_title'  => thematic_before_title(),
    	'after_title'   => thematic_after_title() ); 
    
    register_sidebar($args2);
    
    //display the sidebar
    function child_belowcontent_aside() {
    	if( is_home() ){
    		if (is_active_sidebar('child-below-content')) {
    			echo thematic_before_widget_area('child-below-content');
    			dynamic_sidebar('child-below-content');
    			echo thematic_after_widget_area('child-below-content');
    		}
    
    	}
    }
    
    add_action('thematic_belowcontent', 'child_belowcontent_aside');

    The sidebar displays fine without the conditional tags but I only need the sidebar to display in the home page.

    I did a similar thing with the thematic_abovecontent() hook and it works perfectly, I took a gander at the thematic functions.php and they both work the same way except one is called befor the index loop and the other is called after the index loop

Viewing 6 replies - 1 through 6 (of 6 total)
  • stvwlf

    (@stvwlf)

    is_home() indicates the posts page. if you have a static home page use is_front_page() instead

    Thread Starter charlesolaes

    (@charlesolaes)

    is front_page returns false, I’m not using a static homepage. my home page should be loading template file home.php, I know the conditional tags work since is_category() returns true so I don’t really understand why is_home isn’t working. The only thing I can think of that might effect this is this chunk of code I placed before the while loop to overwrite the query.

    global $wp_query;
        $args = array_merge( $wp_query->query, array( 'category_name' => 'articles' ) );
        query_posts( $args );

    if this IS indeed the case, what conditional tags can I use then?

    Thanks

    stvwlf

    (@stvwlf)

    yes, that is why is_home() is not working.

    One thing to try:

    global $wp_query;
    $is_home = is_home();   <===== add
        $args = array_merge( $wp_query->query, array( 'category_name' => 'articles' ) );
        query_posts( $args );

    Now you have a variable, $is_home, that holds the value of is_home() from before you modified your query.

    I don’t recall offhand though whether is_home() is true when the home.php template is being used. I seem to remember having an issue with this before.

    If that doesn’t work, try this
    if ( is_page_template( 'home.php' ) )

    Thread Starter charlesolaes

    (@charlesolaes)

    omg you are awesome stvwlf! it worked! so the conditional tags are based off the main query?

    Thanks, you saved me from a 2 day head ache!

    stvwlf

    (@stvwlf)

    Hi

    The way that WordPress works is each page that is to display (whether a post, home, a category page, a static page, whatever) has an already prepared default query executed. WordPress determines what kind of page it is working with based on the page’s URL and the WordPress built in redirection (permalink) system. All of the conditionals (including is_home() ) are set based on this default query.

    query_posts alters or replaces this default query and thus resets all the conditionals to match the revised query. When you use the home page to display a category page, it is no longer the posts page so is_home() is no longer true, and is_category() is true. Thus your original problem.

    What I did is save the state of is_home() before the query was modified. Thus you can tell if you are on the home page even though you are using it for another purpose.

    Here is a good page that describes all of this:
    http://codex.wordpress.org/Function_Reference/WP_Query

    Thread Starter charlesolaes

    (@charlesolaes)

    Thanks man, just when I thought I got WordPress all mapped out, this hits. I guess there’s still loads for me to learn.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘problem with conditional tags’ is closed to new replies.