treehouse : what would you like to learn today?
Web Design Web Development iOS Development

query_posts help

  • Hey there,

    I need some advice. I'm not sure if this the correct way I should be using query_posts but here goes.

    Whenever I submit a post under the category uevent it posts the title over in the sidebar. I did this by using <?php query_posts('cat=-4'); ?> in the main loop(i think it's called) so it doesn't get posted there at all. And I put this in my sidebar <?php query_posts('cat=4&showposts=5'); ?>

    So it lists the title of the 5 most recent posts filed in the uevent category.

    It works great, but I've tried to wrap a div around that query but it doesn't work. When I check the source the div gets placed before the query.

    I try this:

    <div id=\"events\">
    <?php query_posts('cat=4&showposts=5'); ?>
    </div>


    This is the output:

    [b]<div id=\"events\">  </div>[/b]
    <ul>
    <li>
    <a href=\"http://localhost/wordpress/?p=91\">testing 123</a>
    </li>
    <li>
    </li>
    <li>
    </li>
    </ul>


    For me to add a div or a class do I need to feed it as an argument into that function?

    Hope you understand what I mean.

    TIA!
  • Problem is resolved now. It was just me being silly.

    I should of wrapped this instead:

    <ul>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href=\"<?php the_permalink() ?>\"><?php the_title(); ?></a></li>
    <?php endwhile;?>
    </ul>
  • well done, sometimes we find our own answers after asking questions, I used to do that in a java forum