• Resolved jfriesen

    (@jfriesen)


    I would like to have an archive page display ALL posts sorted alphabetically. I’ve read these:

    http://codex.wordpress.org/Alphabetizing_Posts
    http://wordpress.org/support/topic/22801

    but they deal with category and index pages, templates that have the loop.

    Here’s the code of my archive template:

    <?php
    /*
    Template Name: Artists A-Z
    */
    ?>
    <?php get_header(); ?>
    <h1>Artists A-Z</h1>
    <div class="storycontent">
    <ul>
    <?php
    wp_get_archives('type=postbypost&sort=post_title&order=ASC');
    ?>
    </ul>
    </div></div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I got the wp_get_archives code from here in the Forum. Curiously, the TYPE and SORT parameters aren’t listed in the Codex for this function:
    http://codex.wordpress.org/Template_Tags/wp_get_archives

    How can I achieve an alphabetized archive page that lists all posts?

    THX!
    JF 😉

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter jfriesen

    (@jfriesen)

    Hmm, I wasn’t being accurate at all: that isn’t an archive template, it’s a PAGE template.

    I don’t really care if it’s a page or an archive, I just need the desired output: an alphebetized listing of ALL posts on the site.

    Can anyone point the way?

    I tried the following, but the result is one link (a link to the page itself).

    <?php
    /*
    Template Name: Artists A-Z
    */
    ?>
    <?php get_header(); ?>
    <h1>Artists A-Z</h1>
    <?php
    $posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="storycontent">
    <ul>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?>
    </a></li>
    </ul>
    </div>
    <?php endwhile; else: ?>
    <p>
    <?php _e('Sorry, there are no artists in this category yet.'); ?>
    </p>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    All comments appreciated!
    JF 😉

    Initializing The Loop with this:

    <?php query_posts('orderby=title&order=asc&showposts=-1'); ?>

    Should do.

    (Note I swapped out posts_per_page for showposts, which is the more appropriate argument for this. I also removed $query_string from your arguments, as it’s not defined in your code. If you’re defining it somewhere else, just put it back.)

    And here is a brand new plugin for “alphabetizing”
    http://www.nateomedia.com/wordpress/wp-snap

    It has been posted 9 hours ago in the forum:
    http://wordpress.org/support/topic/66939?replies=1

    Thread Starter jfriesen

    (@jfriesen)

    Thank you for your replies!

    I tried your code, Kafkaesqui, but it returned a list of PAGES rather than posts. I suspect this is because a page is making the query.

    Similarly, I don’t think WP-snap will work because while it alphebetizes categories, it appears to do it category at a time–I don’t see any way to configure it that would display ALL posts alphabetically. When I called it from my page, it generated all sorts of SQL errors, again probably because a page was calling the plugin.

    All comments appreciated!
    thanks,
    JF 😉

    Thread Starter jfriesen

    (@jfriesen)

    Problem solved! Thanks again to Kafkaesqui: it was an older post of yours that I just found that did the trick:
    http://wordpress.org/support/topic/29255

    I copied the function code to my-hacks.php, and renamed the function to get_alpha_archives. I called the function just as you would with get_archives:
    http://codex.wordpress.org/Template_Tags/get_archives

    and it worked!!

    Thanks again!
    JF 😉

    Yes, WP-SNAP! was created specifically for use in categories, but I certainly could modify it to work with pages as well. I’ll add it to my to-do list. 🙂

    (Actually, thinking about it, I think it would only take about one line of code… I’ll tinker later tonight.)

    I was right, updating WP-SNAP! to include the ability to work on Pages was a… snap. One line of code and BAM! An exciting world of new possibilities.

    Get WP-SNAP! version 0.2 right here:

    http://www.nateomedia.com/wordpress/wp-snap

    jfriesen, I’m certainly glad you found a solution, but something else must be getting in the way if the query_posts() code I gave above is not working.

    Dgold

    (@dgold)

    the wp-snap plugin is neat but it seemed like it sorted by category (does it also do “all categories combined in 1”?)

    So I just used the query_posts() that Karkaesqui provided. It worked on a *page* for me! So I was able to accomplish what the original poster asked for, an alphabetical index of all my post titles on an archives page. I just made a new page-template for it, alphabeticalarchives, and selected that template in the Manage Pages drop-down menu.

    Thanks for the code once again K.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘alphabetical archives’ is closed to new replies.