ThemeShaper Forums » Thematic

[closed]

Sidebar gone walkabout after adding second loop to homepage

(9 posts)
  • Started 3 years ago by RichardB
  • Latest reply from RichardB
  • This topic is resolved
  1. RichardB
    Member

    Hi guys,

    I'm brand new to all this and these forums are completely amazing. I'm re-designing our company's website (we're an arts festival), using a thematic child theme. I have added a second loop to my homepage, which works great, except that its presence there has caused the sidebar to disappear underneath it - see here: www.lichfieldfestival.org/testingtestingtesting. I can't see any logic for this so need your expert help!

    Here's the code for my loops in functions.php:
    // Add featured posts to the frontpage underneath the featured content slideshow
    function LFS_indexloop() {
    query_posts("showposts=3&cat=349");
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    <?php thematic_postheader();
    if (has_post_thumbnail()) {
    the_post_thumbnail('homepage-featured-image');
    } ?>
    </div><!-- .post -->
    <?php endwhile; else: ?>
    <h2>Eek</h2>
    <p>There are no posts to show!</p>
    <?php endif;
    wp_reset_query();
    }

    // Add Latest News loop underneath the featured posts
    function LFS_Latest_News() {
    query_posts("showposts=3&cat=31");
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID() ?>" class="<php thematic_post_class() ?>">
    <?php thematic_postheader();
    if (has_post_thumbnail()) {
    the_post_thumbnail('latest-news-image');
    }?>
    <div class="entry-content">
    <?php the_excerpt(); ?>
    " class="more"><?php echo more_text() ?>
    </div><!-- .post -->
    <?php endwhile; else: ?>
    <h2>Oh dear!</h2>
    <p> Nothing's happening here right now, call again later.</p>
    <?php endif;
    wp_reset_query();
    }

    and here are the action loops in home.php (in my child theme directory):

    <div id="container">

    <?php thematic_abovecontent(); ?>

    <div id="content">

    <?php

    // create the navigation above the content
    thematic_navigation_above();

    // calling the widget area 'index-top'
    get_sidebar('index-top');

    // calling the widget area 'index-bottom'
    get_sidebar('index-bottom');

    // action hook for placing content above the index loop
    thematic_above_indexloop();

    // action hook creating the index loop
    //thematic_indexloop();
    //A CUSTOM HOMEPAGE LOOP
    LFS_indexloop();

    //action hook adding news loop below the featured loop
    LFS_Latest_News();

    // action hook for placing content below the index loop
    thematic_below_indexloop();

    // create the navigation below the content
    thematic_navigation_below();

    ?>

    </div><!-- #content -->

    <?php thematic_belowcontent(); ?>

    </div><!-- #container -->

    If anyone has any idea why the sidebar is going walkabout and could point me to a solution, I would be insanely grateful. Thank you.

    Posted 3 years ago #
  2. you don't have thematic_sidebar()

    take a look at index.php for a good start

    Posted 3 years ago #
  3. RichardB
    Member

    Sorry Helga, didn't give the full story -> this is my entire home.php (thematic_sidebar() included):

    <?php

    // calling the header.php
    get_header();

    // action hook for placing content above #container
    thematic_abovecontainer();

    ?>

    <div id="container">

    <?php thematic_abovecontent(); ?>

    <div id="content">

    <?php

    // create the navigation above the content
    thematic_navigation_above();

    // calling the widget area 'index-top'
    get_sidebar('index-top');

    // calling the widget area 'index-bottom'
    get_sidebar('index-bottom');

    // action hook for placing content above the index loop
    thematic_above_indexloop();

    // action hook creating the index loop
    //thematic_indexloop();
    //A CUSTOM HOMEPAGE LOOP
    LFS_indexloop();LFS_Latest_News();

    // action hook for placing content below the index loop
    thematic_below_indexloop();

    // create the navigation below the content
    thematic_navigation_below();

    ?>

    </div><!-- #content -->

    <?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('homepage');

    ?>

    The sidebar is there, it's just when the second loop is added it is moved below the container, rather than sitting alongside it. If I remove the second loop it returns very happily to where it should be. I've checked and it isn't a CSS issue. Just a little perplexed atm! Any further ideas? Thank you.

    Posted 3 years ago #
  4. "is isn't a CSS issue" - so if you view source it isn't there at all?

    do you have any functions that filter off the sidebar?

    also- i try to avoid query_posts at all costs b/c it often does weird stuff that you spend hours trying to get around. get_posts does almost exactly the same thing and never monkeys with your original query. yeah wp_reset_query is supposed to do it, but i always have problems.

    http://codex.wordpress.org/Template_Tags/get_posts

    use that for the second loop for sure.

    the first loop i think you can put in childtheme_override_index_loop()

    but before the if has_posts, while bits do a merge of your adjusted params w/ the current query params

    http://codex.wordpress.org/Function_Reference/wp_parse_args

    it would go something like

    function childtheme_override_index_loop() {
    global $wp_query;
    
    //adjust query
    $my_args = array( 'posts_per_page' => 3,
    				cat=>349 );
    
    $args = wp_parse_args( $my_args, $wp_query->query);
    
    query_posts( $args );
    
    	if (have_posts()) : 
    
    		while (have_posts()) : the_post(); ?>
    
    			<a href="<?php echo get_permalink();?>"><?php the_title();?></a><br />
    
    		<?php endwhile;
    
    	endif;
    
    }

    untested as it is a simplified version of something i just did for a category loop, so typos are possible.

    Posted 3 years ago #
  5. middlesister
    Member

    Could you maybe post the code for the LFS_Latest_News() loop?
    If you look at the source in firebug, you can see that the News posts are all containing eachother. The sidebar is also contained in that first News post div, and the #footer div is inside #content. Somewhere there is a missing closing </div>.

    Posted 3 years ago #
  6. or that would be an easy solution too... :) but i still stand by the superiority of get_posts() ;)

    Posted 3 years ago #
  7. middlesister
    Member

    heh :)
    I agree with you though, I use get_posts() too. Mostly because i prefer the foreach loop instead of the while:endwhile thingy. Easier to read for my eyes. There is more than one way to skin a cat. ;)

    I didn't know that there were pitfalls with the other way to do it. Good to know.

    Posted 3 years ago #
  8. well in theory if you cache the original query or use wp_reset_query they are supposed to be almost the same. but i just run into fewer problems with get_posts

    @richard still having the problem? your above link doesn't work any more.

    Posted 3 years ago #
  9. RichardB
    Member

    Hi Helga and Middlesister. Thank you, I added a closing </div> and the sidebar returned to its rightful position! I'll mark the topic as resolved (and promptly open another one). Much obliged.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.