WordPress.org

Ready to get started?Download WordPress

Forums

Reverse order the posts in WordPress 2.0 (4 posts)

  1. ulyssesr
    Member
    Posted 8 years ago #

    I would like to reverse order the posts in one of my WordPress 2.0 installations. I prefer not to hack the WordPress core files such as wp-blog-header.php. I also like to avoid using my-hacks.php. Is there a simple way to reverse the posts making changes only to my theme files, preferably the index.php file.

    Here's my theme 'index.php' file. Any help is appreciated.

    [code]
    <?php get_header(); ?>

    <div id="content" class="narrowcolumn">
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php require('post.php'); ?>
    <?php endwhile; ?>

    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','« Previous Entries') ?></div>
    <div class="alignright"><?php posts_nav_link('','Next Entries »','') ?></div>
    </div>

    <?php else : ?>

    <h2 class="center">Not Found</h2>
    <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>

    <?php endif; ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>
    [/code]

  2. Jeff Starr
    Member
    Posted 8 years ago #

    If you change your mind about not wanting to hack any core files, there is a handy little tutorial for reversing the order of post navigation links at perishablepress.com

  3. syncbox
    Member
    Posted 8 years ago #

    I think that the answer is on this page:

    http://codex.wordpress.org/Template_Tags/query_posts

    The wp_query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category). If you want to preserve that information, you can use the variable $query_string in the call to query_posts().

    For example, to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

    query_posts($query_string . "&order=ASC")

    or DESC, depending upon what you want.

    HTH

  4. Jeff Starr
    Member
    Posted 7 years ago #

    To reverse the chronological order of the entire set of posts, such that the "oldest" posts appear on the first page of the blog, use the method reiterated by syncbox.

    To reverse the chronological order of post navigation, such that the "newest" posts appear on the first page of the blog, the tutorial provided at Perishable Press works wonders.

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.