WordPress.org

Ready to get started?Download WordPress

Forums

Alphabetical Posts in the Archive Page (17 posts)

  1. TomBarnett
    Member
    Posted 7 years ago #

    Having searched and searched I haven't yet found a solution that solves my (what should be very simple) problem. Basically, all I want is a list of all my posts but in alphabetical order on my archive page. My site is doing song reviews in a somewhat satirical manner and this seems more appropriate than something time based. I don't want it category specific or on my index page like some solutions have told me, all i want is something that lists all of the posts - in alphabetical order.

    I've tried <?php wp_get_archives('type=postbypost&orderby=title&order=asc'); ?> but that just hasn't done it.

    edit. and yes i know i've posted this in the wrong section, but i don't seem to be able to move it. my bad.

  2. moshu
    Member
    Posted 7 years ago #

    but that just hasn't done it.

    What does that exactly mean?

  3. TomBarnett
    Member
    Posted 7 years ago #

    As in it just hasn't done what I wanted it to do.

  4. Dgold
    Member
    Posted 7 years ago #

    before the Loops starts with this

    <?php while (have_posts()) : the_post(); ?>

    put this

    <?php
    // we add this, to show all posts in our
    // Glossary sorted alphabetically
    $posts = query_posts($query_string .
    '&orderby=title&order=asc&posts_per_page=-1'); ?>

    Works for me on a site that archives Poems sorted by title. Hope this helps!

  5. TomBarnett
    Member
    Posted 7 years ago #

    But there is no loop on my archives page!

    (this is archives.php we are talking about)

  6. moshu
    Member
    Posted 7 years ago #

    (this is archives.php we are talking about)

    Those were the details I was asking for from the beginning.

    And you are putting there parameters that doesn't exist for this template tag:
    http://codex.wordpress.org/Template_Tags/wp_get_archives
    (which means: it displays the posts but not in alphabetical order, to explain it - since you were reluctant to do it)

  7. jebbika
    Member
    Posted 6 years ago #

    so there's no way to put them alphabetically?

  8. Roy
    Member
    Posted 6 years ago #

    I'm trying to do the same thing. I have a page with the simple function:
    <?php wp_get_archives('type=postbypost&limit=1000'); ?>
    which results in a chronologcal list of all post titles. I would like that list to be alphabetical, so I made the function thus:
    <?php wp_get_archives('type=postbypost&limit=1000&orderby=title&order=asc'); ?>
    The result is the same as without the order and orderby additions, but why is that???

  9. moshu
    Member
    Posted 6 years ago #

    On the Codex page I linked to above... show me where is the order parameter you are using.

  10. Roy
    Member
    Posted 6 years ago #

    ...

    So archive results cannot be alphabetical, not even 'by force'...? What about another function, such as:

    <?php
    $postslist = get_posts('numberposts=1000&order=ASC&orderby=post_title');
    foreach ($postslist as $post) :
    setup_postdata($post);
    the_date();
    echo "<br />";
    the_title();
    the_excerpt();
    endforeach;
    ?>

    It doesn't work at all. Because this is also an archiving function?

  11. moshu
    Member
    Posted 6 years ago #

    I don't know.
    Any template tag that is defined by the WP engine can use ONLY the parameters listed in its description.

    Of course, you may and can build custom queries to show whatever you need - I just can't help not being a coder. Sorry.

  12. Roy
    Member
    Posted 6 years ago #

    Just wondering. I've got a plugin that actually produces an alphabetical list after clicking on a category (it is conveniently called "Sort Categories by Title" and it is written by Mikesmullin.com), so still figure that it should be possible to make what I'm looking for. Mike Smullin uses the following to produce the result:

    add_action('pre_get_posts','sort_categories_by_title');
    
    function sort_categories_by_title($x) {
    	if(is_category()) {
    		$x->query_vars['orderby'] = 'title';
    		$x->query_vars['order'] = 'ASC';
    	}
    }

    Still that simple orderby, but also with the brackets, I can't get the get_archives function to do what I want...

  13. Ivovic
    Member
    Posted 6 years ago #

    ok, so there's no loop on the archive page, but how about creating one?

    if you make a loop and stick it there, you can extract and order any posts you like, in any way you like.

  14. Roy
    Member
    Posted 6 years ago #

    I'm sorry Ivovic, I'm still waiting for that one moment in which PHP becomes clear to me. It all looks so simple, but I still don't understand how it works.

    My archives.php looks like this:
    <?php
    /*
    Template Name: Archives
    */
    ?>

    <?php get_header(); ?>

    <div id="content">

    <div class="post">
    <h2><?php _e('Archives by Month') ?>:</h2>

      <?php wp_get_archives('type=monthly'); ?>

    <h2><?php _e('Archives by Subject') ?>:</h2>

      <?php wp_list_cats(); ?>

    </div>
    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?> `

    and the page on which I want to show just a long list of all post titles in alphabetical order, now looks like this:

    <?php
    /*
    Template Name: Archives
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content">
    <div class="post">
    <h2><?php _e('A chronological list of reviews to scroll through') ?>:</h2>
      <ul>
    	<?php wp_get_archives('type=postbypost&limit=1000'); ?>
      </ul>
    </div>
    </div>	
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    The 'working function' to me seems to be get_archives and ordered postbypost, so that would mean that this is the place to ask for an alternative ordering, but this is obviously too simple a thought. The overview.php uses archives.php as template, but the result of clicking on the overview is not "archives by month" and not "archives by subject", so obviously it is the overview.php which is used to find the information and order it. The plugin I mentioned earlier supposedly also uses the archives.php template but does result in an alphabetical list for one category. My Fluid Blue theme also has an archive.php which could also be responsible for the way the results are shown. This one is substantially longer than the archiveS.php.

    If <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> is 'the Loop' why would putting that on top of the archive(s).php make a difference? Do the extra requests for a different output have to be put into 'the loop' or does 'the loop' make the page accept extra requests and what else does have to be changed in the archive(s).php to make it do what I want?

    It bothers me that I can't figure this thing out, while it looks so simple. I hope that some thing will make me understand the logic of it all so that I can start working on other things...............

  15. Roy
    Member
    Posted 6 years ago #

    Ah, all the time that I spent making something and now I run into plugin that does even more than I wanted (making an alphabet)!

  16. arkane8
    Member
    Posted 6 years ago #

    I know this was an old post, but just in case people don't know, WordPress includes the ability to pull up an entire list of post titles in alphabetical order using the archives.

    The syntax is:

    <?php
    wp_get_archives('type=postbypost&type=alpha&order=ASC');
    ?>
  17. jcrens8392
    Member
    Posted 6 years ago #

    You could have also created a loop in the archives page with a custom query like this:

    <?php
    if(have_posts()):
        query_posts('orderby=title&order=ASC&posts_per_page=-1');
        while(have_posts()): the_post(); ?>
            <h2><?php the_title(); ?></h2>
        <?php endwhile; endif; ?>

    May require some tweaking, but that'll display all posts in alphabetical order by title with all posts displayed on 1 page.

Topic Closed

This topic has been closed to new replies.

About this Topic