WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts in a table with 3 columns (11 posts)

  1. Merano
    Member
    Posted 8 years ago #

    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 ;-)

  2. Jonathan Dingman
    Member
    Posted 8 years ago #

    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}.

  3. Merano
    Member
    Posted 8 years ago #

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

  4. nmallory
    Member
    Posted 8 years ago #

    >>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.

  5. Merano
    Member
    Posted 8 years ago #

    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??

  6. nmallory
    Member
    Posted 8 years ago #

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

  7. Merano
    Member
    Posted 8 years ago #

    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 :-(

  8. Yngwin
    Member
    Posted 8 years ago #

    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.)

  9. Livia
    Member
    Posted 8 years ago #

    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(); ?>

  10. Yngwin
    Member
    Posted 8 years ago #

    Still a shame you're using tables for layout...

  11. x9tripboarder16
    Member
    Posted 7 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic