• Resolved typojinx

    (@typojinx)


    I bet you’re all sick of sidebars going walkabout in conjunction with the pageofposts template, however, I’ve got one myself.

    Here’s the deal;

    See here – https://www.buryandramsbottomartweek.co.uk/news/
    If there is only one post to the news page, the sidebar stays in place on the right.

    If there are two posts, seemingly regardless of the length of the post, the sidebar drops to below the last post on the page and I can’t figure out why.

    If like so many other people, the sidebar was always below the last post, I could understand it.
    But to do it when there is more than one post on the page, is confusing the hell out of me..!

    Can anybody shed some light?

    Here’s the pageofposts code;

    <?php
    /*
    Template Name: PageOfPosts
    */
    get_header(); ?>
    
    <?php
    // page id 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
    //page: 51-news (cat-5), 13-events (cat-3), 15-featured artists (cat-4), 61-venues (cat-6), 140-delivery and collection (cat-7)
    if (is_page('51') ) {
    $cat = array(5);
    } elseif ( is_page('13') ) {
    $cat = array(3);
    } elseif ( is_page('15') ) {
    $cat = array(4);
    } elseif ( is_page('61') ) {
    $cat = array(6);
    } elseif ( is_page('140') ) {
    $cat = array(7);
    
    } else {
    $cat = '';
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 0; // 0 to show stickies
    $args=array(
    'category__in' => $cat,
    'showposts' => $showposts,
    'caller_get_posts' => $do_not_show_stickies
    );
    $my_query = new WP_Query($args);
    ?>
    
    <div id="main">
    
    <?php if ( $my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post();; ?>
    
    <?php
    //necessary to show the tags
    global $wp_query;
    $wp_query->in_the_loop = true;
    ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    <p class="post-info">Posted by <?php the_author() ?> | Filed under <?php the_category(', ') ?></p>
    
    <?php the_content(); ?>
    
    <p class="post-footer">
    <?php the_tags('Tags: ', ', ', '<br />'); ?>
    <a href="<?php the_permalink() ?>" class="readmore">Read more</a> |
    <a href="<?php comments_link(); ?>" class="comments">Comments (<?php comments_number('0','1','%'); ?>)</a> |
    <span class="date"><?php the_time('M j, Y') ?></span>
    </p>
    
    <?php endwhile; ?>
    
    <div class="float-left"><?php next_posts_link('&laquo; Older Entries') ?></div>
    <div class="float-right"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    
    <?php else : ?>
    
    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>
    
    <?php endif; ?>
    
    <!-- main ends -->
    </div>
    </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • First, you see this:

    <?php endwhile; ?>
    

    change to:

    </div>
    <?php endwhile; ?>
    

    Then you see this:

    <!-- main ends -->
    </div>
    </div>
    

    Change to:

    <!-- main ends -->
    </div>
    

    Oh and btw, 'showposts' is deprecated. Please use 'posts_per_page'. i.e 'posts_per_page' => $showposts,

    Thread Starter typojinx

    (@typojinx)

    Zeo, you are a gentleman and a scholar.

    Problem solved, thank you very much.

    Just on the matter of deprecated tags, would leaving any other deprecated tags in there cause issues with 2.9.2? Is there a list somewhere on codex with the deprecated tags in?

    No idea.

    I usually add define('WP_DEBUG', true); in wp-config.php if creating or updating a theme. Error notice will be displayed if any. But not recommended to test in a live site.

    Thread Starter typojinx

    (@typojinx)

    Ok, no worries, I’ll make a note of that tip though!

    Thanks for all your help.

    For those who still have a wandering sidebar issue with pageofposts, this is how I solved mine (https://www.theamazingagingmind.com/seniors-people-with-abilities/)

    The div=”content” in the pageofposts was dictating the format of the page, making the text run all the way across the page and hence making the sidebar drop below it. So I changed “content” to “content1” and created a new style for “content1”. The super cool thing about this solution is that I can have a different background–shoot different everything–on this page. So I put an animated gif in the background, creating a header for the page.
    Only problem I have is creating a blank space on the actual page top so the background gif will show. My solution (which I don’t like) was to put a period there, formatted h1. It gave me the space, but the dot is annoying.
    Can anyone show me how to add blank space at the top of a pageofposts?
    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Yet another “pageofposts” sidebar wandering off problem’ is closed to new replies.