WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Chronological sidebar archives (3 posts)

  1. Gohst
    Member
    Posted 7 years ago #

    I've been looking all over for some way to make my sidebar archives chronological. At the moment they are reverse chronological. Eldest post near the bottom of the screen and most recent at the top. I'd like it to be reversed so that the oldest post is at the top and the newest is at the bottom.

    So far I've got this in the sidebar.php file

    <!-- START ARCHIVES -->
    <h2>Archives</h2>
    <ul>
    <?php wp_get_archives('type=postbypost') ?>
    </ul>
    <!-- END ARCHIVES -->

    Try as I might, I can't figure how to get them to reverse the order in which they display. I've read heaps of confusing posts here in the forum, which mostly seemed to be asking something else. I read the support page on wp_get_archives where it said you can make it alphabetical, but it didn't say how, so there was no way for me to go "ok, ill need to do 'this' to make it chronological". Any help which can offer a reasonable solution to my simple request would be very, very appreciated. Thankyou in advance.

  2. Kafkaesqui

    Posted 7 years ago #

    "I read the support page on wp_get_archives where it said you can make it alphabetical"

    Where does it say that *exactly*. If it does, it's wrong and needs to be corrected.

    get_archives/wp_get_archives can only display posts in chronological order, from latest to earliest. It does not offer a parameter to change the sort to ascending order. For that you can try using something like get_posts() in a way that duplicates the output of get_archives(), like:

    <ul>
    <?php
    $arcposts = get_posts('numberposts=-1&orderby=post_date&order=ASC');
    foreach($arcposts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    Note: Setting numberposts to a value of -1 (minus 1) tells WordPress to collect all posts.

  3. Gohst
    Member
    Posted 7 years ago #

    Well, I don't know if it says it *literally* but that's what I got from it. Its over here: http://codex.wordpress.org/Template_Tags/wp_get_archives and where it says "Displays archive list of the last twenty most recent posts listed by post title." the phrase "...by post title" means alphabetically to me.

    I'll try out your code by the way.
    [edit] the -1 thing didn't work, got an error. So I just changed it to 20000. Figure that should keep me safe.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.