• Resolved Filia Libri

    (@filia-libri)


    Hey,

    so, I created – or rather tried to create – a custom theme for my newsletter and came across the following problem:

    <?php foreach ($posts as $post) { setup_postdata($post); ?>...<?php } ?>

    This is the code that displays the number of recent posts as set in the post-part of the theme’s options, right? And whatever I put instead of … is displayed for every single one of those posts (for me it’s always six posts).

    Now, my problem is that apparently most mail clients break every single layout that’s not purely based on tables, meaning that, since I want my six recent posts to be displayed in three rows, always to posts next to each other in one row, I somehow need to put them into different colums of my table-layout. Unfortunately, that simply doesn’t work if each post has the same code… (or I’m too stupid and just overlooked some really simple way to solve this?)

    So, how can I change that foreach ($posts as $post) to something that makes it possible to have a different code for each post? Like:

    <table>
    <tbody>
    <tr>
    <td><?php something to call recent post 1 { ?>...<?php } ?></td>
    <td><?php something to call recent post 2 { ?>...<?php } ?></td>
    </tr>
    <tr>
    <td><?php something to call recent post 3 { ?>...<?php } ?></td>
    <td><?php something to call recent post 4 { ?>...<?php } ?></td>
    </tr>
    <tr>
    <td><?php something to call recent post 5 { ?>...<?php } ?></td>
    <td><?php something to call recent post 6 { ?>...<?php } ?></td>
    </tr>
    </tbody>
    </table>

    Yeah, well, I don’t know anything about php or whatever so I don’t have any idea whether or not something like this is possible, but maybe someone here can help me?

    Thanks a lot ??

    https://www.ads-software.com/plugins/newsletter/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Stefano Lissa

    (@satollo)

    Probably it’s better to use a variable to counter the iteractions and add a row opening/closing when the counter%%2 == 0 or like.

    OR

    <?php
    $i = 0;
    while ($i<count($posts)) {
    $post = $posts[$i];
    setup_postdata($post);
    ?>
    <tr>
    <td>post 1</td>
    <?php
    $i++;
    $post = $posts[$i];
    setup_postdata($post);
    ?>
    <td>post 2</td>
    </tr>
    <?php
    }
    ?>
    Thread Starter Filia Libri

    (@filia-libri)

    Thanks ??

    I just noticed that one of the preinstalled themes has multiple posts in a row… Guess I could have saved myself a lot of frustation if I had noticed that earlier ^^

    I’m now using

    <table>
    <tbody>
    <tr>
    <?php for ($i=0; $i<2; $i++) { $post = $posts[$i]; setup_postdata($post); ?><td>...</td><?php } ?>
    </tr>
    <tr>
    <?php for ($i=2; $i<4; $i++) { $post = $posts[$i]; setup_postdata($post); ?><td>...</td><?php } ?>
    </tr>
    <tr>
    <?php for ($i=4; $i<6; $i++) { $post = $posts[$i]; setup_postdata($post); ?><td>...</td><?php } ?>
    </tr>
    </tbody>
    </table>

    and it’s working perfectly ^^

    Plugin Author Stefano Lissa

    (@satollo)

    Good! Have a nice day, Stefano.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Different code for each post instead of foreach ($posts as $post)?’ is closed to new replies.