• Resolved Hitokage4

    (@hitokage4)


    I currently have a small PHP loop designed to pull the sub pages of the page the loop is on. It works perfectly.

    <div id="resource">
        	<?php query_posts(array('showposts' => 20, 'post_parent' => 1950, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
    			<div class="video_thumbnail"><a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail('case-thumb'); ?></a></div>
    			<div class="video_title"><span class="rc-label"><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php bloginfo('template_url'); ?>/images/blinds-subpage-image.jpg&w=120&h=120&zc=1" alt="<?php the_title(); ?>" /></a></span>
    			<?php the_content();?>
    			<a class="rc-button" target="_blank" href="<?php the_permalink(); ?>">Learn More</a></div><div class="clear"></div>
        	<?php } ?>
    	</div>

    The problem is for some reason this code is stopping the sidebar from appearing.

    <div id="subRight">
    	<?php get_sidebar(); ?>
    </div><!--subRight-->

    If I remove the loop code and leave the div blank, the sidebar appears so it has to be something involving this code. Any thoughts on why this would be a problem? Thank you!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Are you modifying the main query in the page template file?

    Thread Starter Hitokage4

    (@hitokage4)

    No, this is our own unique template page.

    I understand that it’s a custom page template file but are you modifying the main query or is this a secondary query/loop?

    Thread Starter Hitokage4

    (@hitokage4)

    Oh sorry I misunderstood. This:

    <?php
    		/* Run the loop to output the page.
    		 * If you want to overload this in a child theme then include a file
    		 * called loop-page.php and that will be used instead.
    		 */
    		get_template_part( 'loop', 'page' );
    	?>

    is separate above the loop I am using. Otherwise the code I wrote, the get sidebar, and get footer are the only other PHP on the page.

    In that case, you should not be using query_posts() in your custom code. You should be using get_posts() or WP_Query(). See:
    https://codex.www.ads-software.com/Function_Reference/get_posts
    https://codex.www.ads-software.com/Function_Reference/WP_Query

    Thread Starter Hitokage4

    (@hitokage4)

    Thank you for helping me, btw.

    If I use ‘get_posts’, why will it not pull the featured image or content? (title works though, how weird) Or does get_posts use something different?

    (WP_Query breaks everything all together.)

    I need it to pull the featured image, the content, and the title.

    why will it not pull the featured image or content?

    Check the page I linked to above. It’s all explained in there.

    Thread Starter Hitokage4

    (@hitokage4)

    If I change my query_posts to get_posts, and as outlined in the page you sent change the_content to post_content, the_title to post_title, and there isn’t even an open for the thumbnail, it promptly breaks the entire page.

    Thread Starter Hitokage4

    (@hitokage4)

    Forgive me, I’m also VERY new to WP coding so please forgive me if I seem a bit dense to something.

    Thread Starter Hitokage4

    (@hitokage4)

    So now I have this:

    <div id="resource">
        	<?php get_posts(array('showposts' => 20, 'post_parent' => 1950, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
            	<?php
    				$args = array( 'numberposts' => 3 );
    				$lastposts = get_posts( $args );
    				foreach($lastposts as $post) : setup_postdata($post); ?>
    					<div class="video_thumbnail"><a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail('case-thumb'); ?></a></div>
    					<div class="video_title"><span class="rc-label"><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php bloginfo('template_url'); ?>/images/blinds-subpage-image.jpg&w=120&h=120&zc=1" alt="<?php the_title(); ?>" /></a></span>
    					<?php the_content();?>
    					<a class="rc-button" target="_blank" href="<?php the_permalink(); ?>">Learn More</a></div><div class="clear"></div>
    				<?php endforeach; ?>
    		<?php } ?>
    	</div>

    Which is… actually pulling posts, not PAGES as I need. (and had working with ‘query_posts’).

    Thread Starter Hitokage4

    (@hitokage4)

    Ah! Once I replaced the internal loop with the array from the first loop, it is pulling what is required.

    THANK YOU! You were incredibly helpful and kind. This newbie is in your debt.

    Glad to hear that you got it sorted. ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Sidebar Not Showing Due to PHP Loop’ is closed to new replies.