• I have a static front page on which I’m using query_posts to list the latest post:

    <?php if (is_front_page()) query_posts('showposts=1'); ?>

    All of my site is designed with two navigation bars – one at the top of the page, which comes before The Loop, and another at the bottom of the page, which comes after The Loop. They’re both called in the same way:

    wp_list_pages('title_li=&sort_column=menu_order');

    The problem is that their output is different on the front page. The one at the top works correctly – it adds “current_page_item” to the current page

    • . But the one on the bottom does not. Instead, it adds “current_page_parent” to the BLOG page
    • . For other pages, everything works correctly.

      I’ve narrowed the problem down to query_posts actually changing the type of the page that it’s called on, e.g. putting the following on the front page:

      <?php if (is_front_page()) echo 'Test 1'; ?>
      <?php if (is_front_page()) query_posts('showposts=1'); ?>
      <?php if (is_front_page()) echo 'Test 2'; ?>

      …will print out “Test 1”, but not “Test 2”. Why is that? What can I do to keep query_posts from changing my page type? Or is there a workaround to calling query_posts to get the latest post on my static front page?

      Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I had the same issue, but I think i’ve got it. I haven’t tested it much (it’s late, i’m tired, and this has taken awhile to figure out). But this seems to work:

    <?php
    $myPosts = new WP_Query();
    $myPosts->query('showposts=1');  
    
    while ($myPosts->have_posts()) : $myPosts->the_post(); ?>
    the_title();
    the_content();
    endwhile;
    ?>

    That seems to resolve the issue of having the page list, after the post query.

    UPDATE: …Pagination doesn’t seem to work when adding &showposts=3. Back the the drawing board.

    I have a similar problem:
    http://wordpress.org/support/topic/323143?replies=3

    I basically want to include the pages defined content/comments area at the end of the page.

    So it will display all the posts in a specific category and then show the comments area for the specific PAGE at the end.

    Found a fix. It keeps the pagination and fixes the wp_list_pages issue that query_post can create.

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('category_name=yourcat&showposts=2'.'&paged='.$paged);
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
      <?php the_title(); ?>
      <?php the_content(); ?>
    <?php endwhile; ?>
    <?php previous_posts_link('&lsaquo; Previous Page | '); next_posts_link('Next Page &rsaquo;'); ?>
    <?php $wp_query = null; $wp_query = $temp; ?>

    The last line basically restores the $wp_query back to its original state. It must be placed after the pagination in order for the pagination to work.

    I gave that a shot but it didn’t work for me. My original problem is here http://wordpress.org/support/topic/244956?replies=3

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Query_posts alters wp_list_pages output’ is closed to new replies.