WordPress.org

Ready to get started?Download WordPress

Forums

How to display earlier posts instead of latest posts (8 posts)

  1. danishanees
    Member
    Posted 1 year ago #

    Hi,
    How can I display earlier or first entered posts instead of latest posts.
    Here is my code:

    <table cellpadding="0" cellspacing="0" border="0">
        	<?php $recent = new WP_Query("cat=8&showposts=2"); while($recent->have_posts()) : $recent->the_post();?>
        	<tr>
            	<td style="padding:10px 0;">
                <?php if (has_post_thumbnail( $post->ID ) ){ ?>
    									<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    									<img src="<?php echo $image[0]; ?>" width="198px" height="96" />
    									<?php }else { ?>
    									<img src="<?php bloginfo('template_url'); ?>/images/event-image.jpg" width="198px" height="96" />
    									<?php } ?>
                </td>
                <td valign="middle" style="vertical-align:middle; padding:0 10px;">
                	<?php the_title(); ?><br />
        <a href="<?php the_permalink() ?>" rel="bookmark"class="whitelink">Click here to read more</a>
                </td>
            </tr>
            <?php endwhile; ?>
        </table>
  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    $recent = new WP_Query("cat=8&showposts=2&orderby=date&order=ASC");

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

  3. cykeltomte
    Member
    Posted 1 year ago #

    I guess what you want is to make an ascending list. Am I correct?

    You could try:

    new WP_Query("cat=8&showposts=2&order=ASC");

    Or maybe:

    $args = array(
    	'posts_per_page' => 2,
    	'cat  => 8,
    	'order' => 'ASC'
    );
    new WP_Query($args);
  4. danishanees
    Member
    Posted 1 year ago #

    Thank you so much ...its working fine :)
    well can you also tell me that is there any option to show shuffle posts or random posts ?

  5. danishanees
    Member
    Posted 1 year ago #

    Thanks alchymyth ...your code also works

  6. cykeltomte
    Member
    Posted 1 year ago #

    You could try adding &orderby=rand,

    new WP_Query("cat=8&showposts=2&orderby=rand");

    Never used it myself though, so not sure how well it works.

  7. danishanees
    Member
    Posted 1 year ago #

    Okay no problem. Let me check this.

  8. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    is there any option to show shuffle posts or random posts ?

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

    all query parameters are listed here http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.