list wordpress post titles from one category in multiple columns in alphabetical order

I am trying to build a kind of archive of my client’s projects, to display at the bottom of each page, exactly like is done in the ‘Experience’ section here: http://toth.com/#experience – except that in my case I only need the full list of projects, not the sub-headings or any other structure.

I have things setup so that each of my client’s projects is a post. So I need a way to display the titles of the posts, from the category I’ve created ‘Work Archive’ (so that the client can add and remove things from the archive easily, by checking/unchecking the category box in each post), in vertical alphabetical order, across four columns which automatically resize to fill the container equally. Each post title in the archive also needs to link to the post, obviously.

Read More

I have been scouring the net for this for days, and while I’ve found pieces of code which look like they’ll help, it seems impossible (with my limited PHP knowledge) to integrate them to fulfill all of my requirements. I have also looked into many WordPress plugins, with again no success. While I’ll accept any solution, this is something that ideally I’d rather solve at the PHP/template level, to keep things as hidden from the client backend as possible.

Any help on this VERY much appreciated.

Related posts

Leave a Reply

2 comments

  1. It sounds like the best way to do this might be to set up a new WP Query object. More info on this here:
    http://codex.wordpress.org/Class_Reference/WP_Query

    <?php
    
    $args = 'category_name=work-archive&orderby=title&order=asc&posts_per_page=9999';
    // assuming 'work-archive' is the slug to your category, we are also doing ascending order by title (a,b,c,d), and pulling 9999 posts (hopefully that is more than the number of posts you have!)
    
    // The Query
    $query = new WP_Query( $args );
    
    // Keeping track of the count
    $count = 0;
    
    // Number of items per column
    $num_per_column = round($query->post_count / 4); // dividing total by columns
    
    // The Loop
    if ( $query->have_posts() ) : ?>
        <ul>
        <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    
            <?php if ( $count % $num_per_column == 0 ) : // If the current count is up to it's limit throw in a new column ?>
        </ul>
        <ul>
            <?php endif; ?> 
    
            <li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
    
            <?php $count++; // Increment counter ?>
    
        <?php endwhile; ?>
        </ul>
    <?php endif; 
    
    /* Restore original Post Data */
    wp_reset_postdata();
    
    ?>
    

    Finish it off w/ some CSS!

  2. To fix the opened ul change the condition for this :

    if ( $count % $num_per_column == 0 && $count != 0)
    

    It will prevent the closing of the ul on the first pass