Results 1 to 3 of 3

Thread: post variable issue

  1. #1
    slee is offline Here For The Peanuts
    Join Date
    Apr 2010
    Location
    UK
    Posts
    106

    Default post variable issue

    I have a function to display the children of the page in the sidebar php file using wp_list_pages:

    Code:
    global $post; ?>
            <div id="subChildren">
            <?php if($post->post_parent)
            $children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->post_parent."&echo=0"); else
            $children = wp_list_pages("sort_column=menu_order&title_li=&child_of=".$post->ID."&echo=0");
            if ($children) { ?>
            
            <ul id="submenu">
            <?php echo $children; ?>
             
            </ul>
    I have also created a shortcode that shows a custom post type using query posts:

    Code:
    function casestudy_shortcode()
        {
        extract(shortcode_atts(array(
                'type' => 'case_studies',
                'limit' => '1',
                'case' => '',
                'size' => 'small'
                ),$atts));
         
                //The Query
            query_posts('post_type='.$type.'&showposts='.$limit.'&p='.$case);
     
            //The Loop
           if ( have_posts() ) : while ( have_posts() ) : the_post();
                       //return sb_post_image('100','100');
                    //the_post_thumbnail('portfolio'); 
                    return  "<div class='".$size."'><a href=\"".get_permalink()."\">".get_the_title()."</a>" . get_the_excerpt() ."</div>";;
          
            endwhile; else:
        endif;
         
            wp_reset_query();    
            
        }
        add_shortcode('casestudy', 'casestudy_shortcode');
    The problem I have is that when teh shortcode is in a page it makes the sub pages not show up. I assume it is overriding the $post variable.


    I have tried using wp_query and get_posts for teh shortcode but i get the same result.

    Is there a way around this?
    Last edited by slee; 06-15-2011 at 11:27 AM.

  2. #2
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Don't use query_posts() for secondary loops; it is intended ONLY for modifying the main Loop.

    Instead, instantiate a new WP_Query, or use get_posts().
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  3. #3
    slee is offline Here For The Peanuts
    Join Date
    Apr 2010
    Location
    UK
    Posts
    106

    Default

    I tried many combinations to try and get it to work and in the end it was because I had the reset in the wrong place ha!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •