Support » Fixing WordPress » Splitting category links into two even columns

  • I have a category page displaying a list of all my categories and within each a list of post links. The problem i’m having is some of the lists are too long, and I would like to split each list into two columns. Basically what i’m saying is I need to count how many posts are in each category, divide this by two, display this amount of posts, then display the remainder of the posts in another column. the code i’m using to display the categories is as follows:

    global $wpdb;
    $categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent = '3' ORDER BY name ASC");
    foreach($categories as $category) :
    <h2><a href="<?php echo get_category_link($category->id);?>"><?php echo $category->name; ?></a></h2>
    	<strong><?php echo $category->description; ?></strong>
    <?php global $post;
    $split = ceil( count($posts) / 2 );
    $myposts = get_posts('order=asc&numberposts=999&'."category=$category->id");
    foreach($myposts as $post) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    <?php endforeach; ?>

    Any help on this would be much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Splitting category links into two even columns’ is closed to new replies.