WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help me create multiple columns from a long list of a year of archives - please! (4 posts)

  1. stooryduster
    Member
    Posted 4 years ago #

    I have a long list of 52 date word pairs that stretch the length of the page. I'd like to split it into three or four columns but I don't have the scripting knowledge to achieve it. The existing code used to generate the list is below. Inside a table with two columns.

    I'm OK with CSS and html.

    On the page it is a tall narrow row as a "mm dd | word" one above the other 52 odd in all. Too long and thin an item. Would look better three or four columns side by side. Is this possible?

    <table class="month-table">
    			<?php $comicArchive = new WP_Query(); $comicArchive->query('showposts=10000&cat='.get_all_comic_categories_as_cat_string().'&year='.$archive_year);
    			while ($comicArchive->have_posts()) : $comicArchive->the_post() ?>
    				<tr><td class="archive-date"><?php the_time('M j') ?></td><td class="archive-title"><a href="<?php echo get_permalink($post->ID) ?>" rel="bookmark" title="Permanent Link: <?php the_title() ?>"><?php the_title() ?></a></td></tr>
    			<?php endwhile; ?>
    		</table>

    Please help.

  2. stvwlf
    Member
    Posted 4 years ago #

    Hi
    Think I got this right. This code displays 4 table cells between each table row, with one post per table cell. If you decide you want 3 posts per row rather than 4 change % 4 to % 3 in three places.

    How it works: It keeps track of the # of posts it has processed and with each post divides the # processed by 4. When the remainder of that calculation is 0 it knows it has processed 4 posts and so close the current <tr> and starts a new row.

    <table class="month-table">
      <?php
      $comicArchive = new WP_Query();
      $comicArchive->query('showposts=-1&cat='.get_all_comic_categories_as_cat_string().'&year='.$archive_year);
      $i = 0;
      echo '<tr>';
      while ($comicArchive->have_posts()) : $comicArchive->the_post();
        $i++;
        if ( ($i+1 % 4) == 0 ) {
          echo '<tr>';
        } ?>
        <td class="archive-date"><?php the_time('M j') ?></td><td class="archive-title"><a href="<?php echo get_permalink($post->ID) ?>" rel="bookmark" title="Permanent Link: <?php the_title() ?>"><?php the_title() ?></a></td>
        <?php if ( ($i % 4) == 0 ) {
    	echo '</tr>' . "\n";
        }
      endwhile;
      if ( ($i % 4) != 0 ) {
        echo '</tr>' . "\n";
      } ?>
    </table>
  3. stooryduster
    Member
    Posted 4 years ago #

    Thanks for the swift response. I'm off to try it. I'll report back if it works.

    As a thank you have a look at some of the stuff on http://www.stooryduster.co.uk/word – it will make you laugh at least once.

    I'm working to transfer all this into WordPress along with the Comicpress theme but trying to control the look of the thing is hard work. I'm particular about detail, being a designer.

    Cheers

  4. stooryduster
    Member
    Posted 4 years ago #

    Converting a long list running down the page into a more manageable four columns through php.

    Spanking! Thanks. Problem solved. That is once I added the code to the correct php file after several wrong attempts. What's worse I'd even created a particular file with an easily recogniseable name. Doh!

    The lesson learned is to keep a log of all modifications. Mod Log. You'll forget even after one day otherwise - imagine when the time comes to upgrade weeks hence, horrible. Make comments in the css and code too, explaining hacks and enclosing them. I know the experienced folk already do - and as a help to the rest of us.

    Cheers

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic