WordPress.org

Ready to get started?Download WordPress

Forums

Show all posts, alphabetically (5 posts)

  1. gulliver
    Member
    Posted 2 years ago #

    I know this has been asked-and-answered by others, but I'm not able to get any of the sugegstions working.

    I want to create a custom page which lists every post, sorted alphabetically rather than by date.

    How? Please, thanks, etc.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    - create a page template:
    http://codex.wordpress.org/Pages#Page_Templates
    (possibly starting with a copy of page.php or single.php or index.php)

    - add a custom query:
    http://codex.wordpress.org/Class_Reference/WP_Query

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

    example:
    $all_posts = new WP_Query( array( 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title' ) );

    what theme are you working with?

  3. gulliver
    Member
    Posted 2 years ago #

    Thanks. That helped. Appreciated.

    I initially tried:

    <?php
    $all_posts = new WP_Query( array( 'posts_per_page' => -1,  'orderby' => 'title' , 'order' => 'ASC') );
    while ( have_posts() ) : the_post(); ?>
    <p><?php the_title() ?></p>
    <?php endwhile; ?>

    But it didn't work - although I can't see why, and it may be my error as it seems to do the same as the code I subsequently used:

    <?php
    $args = array( 'posts_per_page' => -1,  'orderby' => 'title' , 'order' => 'ASC');
    $wp_query = new WP_Query($args);
    while ( have_posts() ) : the_post(); ?>
    <p><?php the_title() ?></p>
    <?php endwhile; ?>

    Now, as expected, I have to paginate that page - so I'm open to suggestions. 'Please, thanks', again.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    have to paginate that page

    with all posts obviously not, but otherwise set 'posts_per_page' to a fixed number, for instance 10, and try:

    <?php
    $args = array( 'posts_per_page' => 10,  'orderby' => 'title' , 'order' => 'ASC', 'paged' => get_query_var('paged') );
    $wp_query = new WP_Query($args);
    while ( have_posts() ) : the_post(); ?>
    <p><?php the_title() ?></p>
    <?php endwhile; ?>

    possibly together with http://codex.wordpress.org/Function_Reference/next_posts_link
    and
    http://codex.wordpress.org/Function_Reference/previous_posts_link

  5. gulliver
    Member
    Posted 2 years ago #

    Thanks, again.

    Your code helped hugely.

    I'd previously used a custom function to replace the next/previous links with 'first 1 2 3 etc last'. It was so long ago that I can't remember much about how it worked, and my brain is currently too shot to re-understand.

    But, there's a line of code which I've been using to paginate elsewhere:

    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("showposts=10&paged=$page"); ?>

    That, with yours, does what's required - provided the integers for 'showposts' and 'posts_per_page' are identical.

    Someday, I'll have a re-read and try to understand this.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.