WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Mini Loop – How to put most recent post on top?

[Resolved] Mini Loop – How to put most recent post on top?

  • rtilney

    @rtilney

    Hi all,

    I’ve got the mini-loop running on a static home page (www.ganning.com/new-1029/index.php) setup as a news listing. It works fine, but the problem is it is displaying the most recent posts at the bottom of the list rather than the top. Does any one know how to change the sort order by most recent post in the mini loop. I’m using the exact code from the WP mini loop instructions.

    I appreciate the help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Kafkaesqui

    @kafkaesqui

    I’m using the exact code from the WP mini loop instructions.

    If you mean this:

    http://codex.wordpress.org/Creating_a_Static_Front_Page#Adding_a_Mini-Loop

    Change:

    ORDER BY 'ID' DESC

    to:

    ORDER BY 'post_date' DESC

    rtilney

    @rtilney

    Hi Kafkaesqui,

    I tried that and it still displays the same order. Here is my exact code:

    <?php
    $how_many=15; //How many posts do you want to show
    require_once(“news/wp-config.php”); // Change this for your path to wp-config.php file ?>

    <id=”whats-new”>
    <?
    $news=$wpdb->get_results(“SELECT ID,post_title FROM $wpdb->posts
    WHERE post_type=\”post\” AND post_status= \”publish\” ORDER BY ‘post_date’ DESC LIMIT “.$how_many);
    foreach($news as $np){
    printf (“%s<br><br>”, $np->ID,$np->post_title);
    }?>

    Any advice?

    Thank you.

    Kafkaesqui

    @kafkaesqui

    Change your $news line to:

    $news=$wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts
    WHERE post_type=\"post\" AND post_status= \"publish\" ORDER BY post_date DESC LIMIT ".$how_many);

    Slipped up suggesting quotes around post_date.

    rtilney

    @rtilney

    Thanks Kafkaesqui, it worked like a charm!

    Where do you find these codes to change

    It was easy to do it in version 2.3.3, but in 2.5 I am lost so far.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Mini Loop – How to put most recent post on top?’ is closed to new replies.
Skip to toolbar