[resolved] query_posts outside the loop? (8 posts)

  1. PeacefulKarl
    Posted 8 years ago #

    I have placed a query_posts element outside the loop in the header so wordpress is calling that tag instead of the loop tag. I am using it to create a list of recent posts. Is there another way of doing this?

    Thanks Karl

  2. Chris_K
    Posted 8 years ago #

    Should we assume this is a dupe of http://wordpress.org/support/topic/111724?replies=1 or are there more details that you haven't provided yet?

  3. PeacefulKarl
    Posted 8 years ago #

    Handy, I've been searching everywhere for an answer for this and just need a little 'nudge'. I guess you might call it a dupe but I prefer to think of it as a call for help...

    I have tried
    and it returns only one post...

    I have tried
    <?php wp_get_archives('type=postbypost&limit=6'); ?>
    and it returns 6 posts but without dates preceding the title...

    I have a link below that points to the permalink and
    <?php the_time('m.j') ?></span> <?php the_title() ?>
    to get the date and title...

    what am I missing here?

    sorry to be that guy that wont quit posting, I swore I would never be him... But tonight I have no answers...

  4. alakhnor
    Posted 8 years ago #

    The correct syntax is :

    $myposts= get_posts('numberposts=6');
    foreach ($mypost as $post) :
  5. PeacefulKarl
    Posted 8 years ago #

    I tried it but got an error message. I am trying to put it in the side bar... does that matter?

  6. PeacefulKarl
    Posted 8 years ago #

    It looks right in the navigation bar at the top right now but is reeking havoc on every page but the index because the query_posts element is outside the loop...

  7. PeacefulKarl
    Posted 8 years ago #

    OK... I got it running sort of... my code looks like this...

    <?php$myposts= get_posts('numberposts=6');?>
    <? foreach ($myposts as $post) : if (have_posts()) :while (have_posts()) : the_post(); ?>
    [ bla... bla...}
    <?php endwhile; endif: ?>
    <?php endforeach;?>

    it has solved part of the problem but now the list only shows the latest post over and over instead of the last six different posts... what did I miss in there?

  8. PeacefulKarl
    Posted 8 years ago #

    WOOOHOO It took some doing but I got it....
    I am no php wizard but your code works...



Topic Closed

This topic has been closed to new replies.

About this Topic