ThemeShaper Forums » Thematic

[closed]

wp_reset_query and meta data for the blog template

(2 posts)
  • Started 3 years ago by helgatheviking
  • Latest reply from helgatheviking
  • This topic is resolved
  1. i'm trying to conditionally kill the sidebar based on meta data. seems to work brilliantly everywhere except with the blog template. if you take a look at the blog template it has the same call:

    // calling the standard sidebar
    thematic_sidebar();

    as every other template so i can't figure out why my filter would not work on this page.

    //will turn off sidebar if layout is set to fullwidth
    function kia_kill_sidebar(){
    	global $layout_metabox;
    	$layout_metabox->the_meta();
    	$layout_meta = $layout_metabox->get_the_value('layout');
    
    	if ("full" == $layout_meta) {
    		return FALSE;
    	} else {
    		return TRUE;
    	}
    
    }
    add_filter('thematic_sidebar','kia_kill_sidebar');

    i realize that this function is dependent on WPAlchemy... but that side is working properly as the above works on other templates... AND the following test function shows the correct values and passes properly through the same conditional.

    function bacon(){
    	global $layout_metabox;
    	$layout_metabox->the_meta();
    
    	$layout_metabox->the_value('layout');
    
    	echo "<p></p>";
    
    	$layout_meta = $layout_metabox->get_the_value('layout');
    
    	 if ("full" == $layout_meta) {
    		echo "yay";
    	} else {
    		echo "wtf";
    	}
    
    }
    add_action('thematic_belowheader','bacon');

    however, it DOES work if i remove the conditionals and just return false- so i suspect it has to do with not yet having a value or the meta somehow getting messed up w/ the index loop? i've tried copying the blog template into my directory and adding wp_reset_query() b/c i have managed to track down that my first function above is pulling the meta data from the first post in the blog template, but that didn't get me anywhere.

    any ideas?

    Posted 3 years ago #
  2. the meta data was being pulled from posts in the blog loop. eventually fixed this by cloning the original query, and then restoring it at the end of the embedded loop as well as using wp_reset_postdata()

    here is my new blog template:

    <?php
    /**
     * Template Name: Blog
     *
     * This template allows you to display the latest posts on any page of the site.
     *
     */
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    		<div id="container">
    
    			<?php thematic_abovecontent();
    
    			echo apply_filters( 'thematic_open_id_content', '<div id="content">' . "\n" );
    
    			//change query
    			$temp = clone $wp_query;
    			$wp_query= null;
    			$wp_query = new WP_Query();
    			$wp_query->query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged ) );
    			$more = 0;
    
    				// create the navigation above the content
                	thematic_navigation_above();
    
                	// calling the widget area 'index-top'
                	get_sidebar('index-top');
    
                	// action hook for placing content above the index loop
                	thematic_above_indexloop();
    
                	// action hook creating the index loop
                	thematic_indexloop();
    
                	// action hook for placing content below the index loop
                	thematic_below_indexloop();
    
                	// calling the widget area 'index-bottom'
                	get_sidebar('index-bottom');
    
                	// create the navigation below the content
                	thematic_navigation_below();
    
                	?>
    
    			</div><!-- #content -->
    
    			<?php //reset query and post data
    			$wp_query = null; $wp_query = clone $temp; wp_reset_postdata(); ?>
    
    			<?php thematic_belowcontent(); ?> 
    
    		</div><!-- #container -->
    
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling the standard sidebar
        thematic_sidebar();
    
        // calling footer.php
        get_footer();
    
    ?>
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.