• Resolved merano

    (@merano)


    Hi everybody,

    I want the posts of a category to be displayed in a table with 3 columns and as many rows as needed.

    I have read about the Loop in the Wiki, but I have no idea how I am gonna have to put everything together… ??

    Any help is appreciated…

    and… yes, I know CSS and DIVs would be better, but I decided to use a table and I won’t change my mind ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • You could do two things. Setup a table outside of the loop <table>{LOOP}</table> or you could create a table for each post.{LOOP}<table>rows-columns</table>{/LOOP}.

    Thread Starter merano

    (@merano)

    I thought that far, too – but I don’t know where to put the <td> and <tr> and stuff…. :-((

    >>yes, I know CSS and DIVs would be better, but I decided to use a table and I won’t change my mind ;-)<<

    But it would be so much easier…

    Check out my personal blog; is this kind of what you want? There’s a link at the bottom to the original theme (Zine), which has no sidebar but uses that 3rd column for more posts.

    Thread Starter merano

    (@merano)

    That’s not what I mean… sorry ??

    For example, if I have 9 posts in one category, I want a table which is 3 colums wide and 3 rows high. In each cell, there should be one post… with 15 posts, the table should be 3 columns wide and 5 rows high…

    eg.

    post 1 | post 2 | post 3 |
    ————————–
    post 4 | post 5 | post 6 |

    and so on…

    know that I mean??

    Yeah. I thought about such a layout previously, but decided against it. Good luck with that.

    Thread Starter merano

    (@merano)

    Ok – I found a page in the WordPress codex about the loop in action – I think I can handle this one and put it into a table…

    As I am not familiar with php at all, I have no idea, how I can tell the template to:
    – make a new row after each 3 posts
    – if there aren’t 3 posts for the last row, fill the space with cells containing & nbsp;

    Does anyone know that??

    I have heard about do while loops and that kinda thing but I have no idea how to use them and how to integrate something like this into TheLoop ??

    I see. I don’t know how to do that with tables (I find them too complicated, because I learnt to do layout with CSS), but I know how to make that work with CSS.

    Just wrap every post in a div, say with a class=post or something and make .post in the stylesheet a float:left with a width a third of the total width. Then add an increment-counter and let every third post clear to line things out. (I can make a demo if needed.)

    I managed to solve it :-))

    <?php
    get_header();
    ?>
    <tr>
    <?php
    $counter = 1;

    if (have_posts()) : while (have_posts()) : the_post(); update_post_caches($posts);
    if ($counter<=3)
    {
    ?>
    <td>
    <h2 id=”post-<?php the_ID(); ?>”>” rel=”bookmark”><?php the_title(); ?></h2>

    <small><?php the_time(‘F jS, Y’); ?> by <?php the_author(); ?></small>

    <div class=’entry’>
    <?php the_content(‘Read the rest of this entry »’); ?>
    </div>

    <p class=’postmetadata’>
    Posted in <?php the_category(‘, ‘); ?>
    |
    <?php edit_post_link(‘Edit’,”,’|‘);?>
    <?php comments_popup_link(‘No Comments ??’, ‘1 Comment ??’, ‘% Comments ??’);?>

    <!–
    <?php trackback_rdf();?>
    –>
    </td>
    <?php
    $counter++;
    }
    else // Counter ist 4
    {
    ?>
    </tr><tr>
    <?php
    $counter=1;
    }

    endwhile;

    if($counter=4)
    {
    ?>
    </td><td class=”col1″> </td><td class=”col2″> </td><td class=”col3″> </td></tr>
    <?php
    }
    elseif($counter=3)
    {
    ?>
    </td><td class=”col3″> </td></tr>
    <?php
    }
    elseif($counter=2)
    {
    ?>
    </td><td class=”col2″> </td><td class=”col3″> </td></tr>
    <?php
    }
    else // counter=1
    {
    ?>
    </td></tr>
    <?php
    }

    else :// falls keine Posts da sind
    {
    ?>
    <?php _e(‘Sorry, no posts matched your criteria.’); ?></td><td> </td><td> </td></tr>
    <?php
    }
    endif;
    ?>
    <?php get_footer(); ?>

    Still a shame you’re using tables for layout…

    Livia, is this for wordpress 1.5 or 2.0? I am trying to do the same thing, but am not having luck with your above code. Could you direct me to the source where you learned of the above code?

    Thanks in advance!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Posts in a table with 3 columns’ is closed to new replies.