www.webdeveloper.com
Results 1 to 2 of 2

Thread: Three columns [WordPress]

  1. #1
    Join Date
    Jan 2010
    Posts
    12

    Three columns [WordPress]

    Hello.

    This is a WORDPRESS question - but if you think you can help - please do!

    I've been searching for a way to split the latest 15 posts from one specific category, into three columns (contaning 5 items each) and display it as links?

    I know that people have shown a way to split ALL CATEGORIES into a number of columns, but that's not what I'm after here.

    Example:
    I have two categories (Music, Food) with 20 posts in each. So, for the music-page i would like to show the last 15 from the music category and vice versa for the Food-page.

    Post 1 Post 6 Post 11
    Post 2 Post 7 Post 12
    Post 3 Post 8 Post 13
    Post 4 Post 9 Post 14
    Post 5 Post 10 Post 15


    I'm currently displaying them like this:


    Code:
    <ul>
    <?php
     global $post;
     $myposts = get_posts('numberposts=15&category=1');
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>
    But it will only give you a long list...and that's ugly

    Any help would be greatly appreciated!
    Kind regards,
    EvilPixy

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    I might do something like:
    PHP Code:
    <div class='multicolumn'>
    <?php
    reset
    ($myposts); // make sure array pointer is at first element
    for($col=1$col<=3$col++)
    {
       echo 
    "<ul class='floater'>\n";
       for(
    $row=1$row<=5$row++)
       {
          
    $post current($myposts);
          
    next($myposts);
          if(
    $post === false)
          {
             break;
          }
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php
       
    }
       echo 
    "</ul>\n";
    }
    ?>
    </div>
    CSS:
    Code:
    .multicolumn {
       overflow: auto; /* needed to clear the contained floats */
    }
    .floater {
       float: left;
       margin: 0 1em 0 0;
    }
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles