Luke Batley
Luke Batley

Reputation: 2402

wordpress get posts from a category

Hi Im trying to make my first wordpress website. i have been trying to bring bat posts from two different categories and display them on the same page. I have it bring the posts back but it keeps putting them in a random order. im wanting a with posts from one categorie and a underneath with posts from another category.

heres what i have got so far

<?php get_head(); ?>

<div id="container">
<?php get_header(); ?>
<?php get_banner(); ?>

    <div class=" center content" role="main">
      <div id="posts">


          <div class="news">
                <?php query_posts('catname=news&showposts=3'); while (have_posts()) : the_post(); the_title(); the_content(); 
                endwhile;?>

                <div class="clear"></div>
          </div>
             <div class="msghead">
            <?php query_posts('catname=msghead&showposts=1'); while (have_posts()) : the_post(); the_title(); the_content(); 
            endwhile;?>

           </div>
        </div>
    </div>

    <div class="sidebardiv">
       <?php get_sidebar(); ?>
    <div class="clear">
    </div>
</div>
</div>
<?php get_footer(); ?>

</div>

Upvotes: 0

Views: 219

Answers (1)

Matthew
Matthew

Reputation: 8416

Have you tried the order and orderby query parameters?

http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Your code might go something like this which orders by date, descending:

<?php query_posts('cat=news&showposts=3&orderby=date'); while (have_posts()) : the_post(); the_title(); the_content(); 
endwhile;?>

Upvotes: 1

Related Questions