WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a website where the client wants a static page displaying information about a certain category. Then under the static information she wants all the posts from that category in a 2 column list.

So I need to have an alphabetically ordered list linking to all the post in a selected category. I have the code to do this, but I need to be able to break the list up in columns. Here is the code I have displaying the post...

if (is_page() ) {
$category = get_post_meta($posts[0]->ID, 'category', true);
if ($category) {
  $cat = get_cat_ID($category);
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $post_per_page = -1; // -1 shows all posts
  $do_not_show_stickies = 1; // 0 to show stickies
    'category__in' => array($cat),
    'orderby' => 'title',
    'order' => 'asc',
    'paged' => $paged,
    'posts_per_page' => $post_per_page,
    'caller_get_posts' => $do_not_show_stickies
  $temp = $wp_query;  // assign orginal query to temp variable for later use   
  $wp_query = null;
  $wp_query = new WP_Query($args); 
  if( have_posts() ) : 
        while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <_li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to          <?php the_title_attribute(); ?>"><?php the_title(); ?></a><_/li>

I know my HTML skills aren't the best, but here is the entire template page...


share|improve this question
Looks like the HTML in your example is a bit mangle: id="post"> is off by itself. Can you update your question to show the full code for your HTML generation? – MikeSchinkel Mar 27 '11 at 15:44
up vote 0 down vote accepted

Updated answer:
Use two floated lists to emulate columns, same approach as previously though.

Template Name: PageOfPosts

get_header(); ?>

<div id="content">
    <div class="t">
        <div class="b">
            <div class="l">
                <div class="r">
                    <div class="bl">
                        <div class="br">
                            <div class="tl">
                                <div class="tr">
                                    <div class="pad">

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

                                        $category = get_post_meta( get_the_ID(), 'category', true); 
                                        $img_style = 'style="width:606;height:34;position: absolute; padding-top:1px; padding-left: 2px; z-index:9999; background: no-repeat;"';

                                        <div class="post" id="post-<?php the_ID(); ?>">

                                            <h1><?php the_title(); ?></h1>
                                            <img src="../wp-content/themes/DD4L/images/leafhr.png" <?php? echo $img_style;?>>
                                            <br />

                                            <div class="entry">
                                                <?php the_content(); ?>
                                                <?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>

                                            <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>


                                        <?php endwhile; ?>

                                        <br /><br />

                                        <?php if( !empty( $category ) ) : ?>

                                        $args = array(
                                            'orderby' => 'title',
                                            'order' => 'asc',
                                            'nopaging' => true,
                                            'ignore_sticky_posts' => true,
                                            'tax_query' => array(
                                                    'taxonomy' => 'category',
                                                    'terms' => array( $category ),
                                                    'field' => 'slug'
                                        $category_query = new WP_Query( $args );

                                        <?php if( $category_query->have_posts() ) :  ?>

                                        $total = $category_query->post_count;
                                        $quart = $total / 4;

                                        if( floor( $quart ) != $quart )
                                            $quart = ceil( $quart );
                                        $counter = 0;

                                        <div class="float-container">
                                            <ul class="alignleft">
                                            <?php while( $category_query->have_posts() ) : $category_query->the_post(); $counter++; ?>

                                                    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>

                                            <?php if( $quart == $counter ) : $counter = 0; ?>

                                            <ul class="alignleft">
                                            <?php endif; ?>

                                            <?php endwhile; ?>

                                            <div class="clear"></div>

                                        <?php endif; ?>

                                        <?php endif; ?>

                                    <div class="clear"></div>


<?php get_sidebar(); ?>
<?php get_footer(); ?>

See edit revision for previous comments and code.

share|improve this answer
@t310s: You are my hero!!! That works great, but there is just one thing. How can have the alphabetical order to be vertical instead of horizontal? Thanks a lot man, this is exactly what I needed. I've looked everywhere for this thing! – Daymon Mar 28 '11 at 13:12
@Daymon - That's exactly what i was referring to when i mentioned not knowing what structure you had in mind, it will need some adjustment to have results listed vertically instead. I'll update the answer shortly, just gotta have a think about how to refactor the code.. :) – t31os Mar 28 '11 at 13:17
@Daymon - Answer updated.. Opted for using the table still but using DIVs as virtual table cells. If you need help creating CSS to pretty up the results, let me know. – t31os Mar 28 '11 at 13:41
@t31os - You're awesome! That listed it in vertical alphabetical order but how do i split into two columns? Could I do 2 separate lists instead of using the DIV tag? Then just float it to the left with whatever width? – Daymon Mar 28 '11 at 13:53
You should have two columns already, the second half of results should list out inside a second table column, is that not happening? – t31os Mar 28 '11 at 14:00

Without really looking at your code and just thinking off the top of my head you could set up a new WP-Query for each column.

In your args set 'posts_per_page' => 10, or however many post permalinks you want to show in each column. Assign a ul or div class to the columns and float them left in your css.

share|improve this answer

You could also use the List Category plugin which will let you insert shortcode into any page or post to show either matching posts by categories or by tags. You can specify order sorting, hide/show excerpts, and much more.

Download: http://wordpress.org/extend/plugins/list-category-posts/

List of full commands: http://foro.picandocodigo.net/discussion/251/list-category-posts-documentation/

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.