Splitting category links into two even columns (4 posts)

  1. jadedstudio
    Posted 7 years ago #

    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.

  2. jadedstudio
    Posted 7 years ago #

    Anyone? This is probably really simple, I just can't figure it out! Any help is greatly appreciated!

  3. jadedstudio
    Posted 7 years ago #

    Is there anybody who might be able to help??

  4. funkboybilly
    Posted 7 years ago #

    I'm looking for exactly the same thing except in 3 columns.

Topic Closed

This topic has been closed to new replies.

About this Topic