• I have a problem with my site, where my header and footer are supposed to expand the width of the page, but the content is suppose to be within a 960px container. The header displays no problem, as well as the footer…on most pages. On my index page, the footer doesn’t display the entire width like it is suppose to, it thinks its nested within the container margin of 960px, and I have no idea why (I checked to ensure all divs, etc were closed, and they are). I narrowed it down the <?php endwhile; ?> statement towards the end.

    Basically, if I remove the <?php endwhile; ?> out of the container div, the footer displays fine, but then the blog posts are all messed up and no longer in proper order.

    The code follows the basic structure

    <?php get_header(); ?>
    
    <div id="container">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    //Content here
    
    <?php endwhile; ?>
    </div>
    
    <?php get_footer(); ?>

    But, if I change the code to something like

    <?php get_header(); ?>
    
    <div id="container">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    //Content here
    
    </div>
    <?php endwhile; ?>
    <?php get_footer(); ?>

    It will work, but all the posts will be jumbled up and out of the container, etc. It’s just a big mess.

    Any help would be greatly appreciated.

    -Rally

Viewing 9 replies - 1 through 9 (of 9 total)
  • You need to provide a url of a working and non-working page.

    The likelihood is that one of the posts has a mismatched div in it.

    Thread Starter RallyGFX

    (@rallygfx)

    All the testing is done locally with wamp atm, so I don’t have a think to show you, I can post the code though?

    Thread Starter RallyGFX

    (@rallygfx)

    Here is the code of the page with the error:

    <?php get_header(); ?>
    
    <div id="content-container">
    
    <?php get_sidebar(); ?>
    <div id="content-container-inner">
        <div id="index2">
            <div id="index-container2">
                        <div id="newsheader">
                            <img src="images/newsheader-img.png" />
                        </div>
                        <div id="divider">
                            <img src="images/divider-long.png" />
                        </div>
            </div>
        </div>
            <?php
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => 1,
    	'paged' => $paged
    );
    query_posts($args);
    
    		 ?>
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <div id="index">
        <div id="index-container">
            <div id="latestnews">
    
                <div id="postingtitle">
                    <div id="newsposting">
                            <div id="commentbubble">
                                <div id="bubbletext">
                                <a href="#"><?php comments_popup_link('0', '1', '%'); ?></a>
                                </div>
                            </div>
                                <h1><a href="<?php the_permalink() ?>"><?php if (strlen($post->post_title) > 40) {
                echo substr(the_title($before = '', $after = '', FALSE), 0, 40) . '...'; } else {
                the_title();
                } ?></a></h1>
    
                    </div>
                        <div id="details">
                        <p><?php include (TEMPLATEPATH . '/inc/meta.php' ); ?></p>
                        </div>
                </div>
    
                <div id="newscontent">
                <p><?php echo content(70); ?></p>
                </div>
                <div id="readmore">
                    <a href="<?php the_permalink() ?>"><img src="images/readmore.png" alt="morenews" /></a>
                </div>
    
        	</div>
        <img src="images/divider-long.png" />
    
        </div>
        <?php endwhile; ?>
        <?php if(function_exists('wp_paginate')) {
                wp_paginate();
            } ?>
        <?php endif; ?> <?php wp_reset_query() ?>
        </div>
    
    </div>
    </div>
    
    <?php get_footer(); ?>
    Thread Starter RallyGFX

    (@rallygfx)

    Also, the pages that are working correctly have the same layout, minus the endwhile statement

    The code you pasted is not correct: Each time through the while loop it will print two opening div tags (div index and div index-container) and only one closing div tag. So you are guaranteed to have mismatched divs.

    Also html tag id’s are supposed to be unique on the page, if you have more than one post you are guaranteed to have multiple divs with the same id, that makes your html invalid.

    Finally, you are running query_posts() in your template which is very inefficient: You are throwing away the results of the query WordPress has already run. But that’s a problem unrelated to your issue.

    Thread Starter RallyGFX

    (@rallygfx)

    Oh, I see. How would I go about fixing some of the issues? I’m still learning WordPress (If that wasn’t already clear ;D ) and not entirely sure of every piece of code yet.

    To fix the first problem, I’m sure just simply moving the endwhile statement out of the second div will allow the two closing divs to be intact?

    As for query_posts() and unique ids, I’m not entirely sure how I would correct that.

    Thanks a ton for the help.

    Thread Starter RallyGFX

    (@rallygfx)

    Never mind, nothing I do seems to correct the issue.

    Thread Starter RallyGFX

    (@rallygfx)

    I can’t even get the content to stay within the container when I change around the div placement. Any ideas on how I would correct the above code?

    It is very difficult to help you without being able to see the resultant content (the generated html) that is going wrong.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Endwhile statement ruining footer layout’ is closed to new replies.