ThemeShaper Forums » Thematic


wp_reset_query and meta data for the blog template

(2 posts)
  • Started 12 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

    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_meta = $layout_metabox->get_the_value('layout');
    	if ("full" == $layout_meta) {
    		return FALSE;
    	} else {
    		return TRUE;

    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;
    	echo "<p></p>";
    	$layout_meta = $layout_metabox->get_the_value('layout');
    	 if ("full" == $layout_meta) {
    		echo "yay";
    	} else {
    		echo "wtf";

    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 12 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:

     * Template Name: Blog
     * This template allows you to display the latest posts on any page of the site.
        // calling the header.php
        // action hook for placing content above #container
    		<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
                	// calling the widget area 'index-top'
                	// action hook for placing content above the index loop
                	// action hook creating the index loop
                	// action hook for placing content below the index loop
                	// calling the widget area 'index-bottom'
                	// create the navigation below the content
    			</div><!-- #content -->
    			<?php //reset query and post data
    			$wp_query = null; $wp_query = clone $temp; wp_reset_postdata(); ?>
    			<?php thematic_belowcontent(); ?> 
    		</div><!-- #container -->
        // action hook for placing content below #container
        // calling the standard sidebar
        // calling footer.php
    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.