• Hi,

    I’m adding a simple responsive layout for a one-page website.

    There’s an Header, Index and Footer file. The header & footer are included on the Index page (maybe this is normal for wordpress sites, im a noob).

    Anyways. I’ve made a simple mobile layout and placed it in the header file. It’s hidden when browsed on a computer, but visible on ipad/phone, and vice versa.

    Now i want to show the latest post on the mobile layout. I’ve used this snippet to grab the latest post from the database.

    <?php
    $catquery = new WP_Query( 'cat=4&posts_per_page=1' );
    while($catquery->have_posts()) : $catquery->the_post();?>
    <h3><?php the_title(); ?></h3>
    <p><?php the_content(); ?></p>
    <?php endwhile; ?>

    But when i paste it in the div, in the mobile layout, where i wanna show the latest post, it works, but at the same time it interferes with the code on the normal site, resulting in this error message:

    Warning: Invalid argument supplied for foreach() in /storage/content/50/163850/gotlundaglass.se/public_html/wp-content/themes/gotlunda_huvudtema/index.php on line 42

    This is the code in Index.php and on line 41-47:

    <?php $openingRows = get_field('openhours'); ?>
    <?php foreach($openingRows as $openingRow): ?>
    <tr>
    <td><?php echo $openingRow['day']; ?></td>
    <td><?php echo $openingRow['times']; ?></td>
    </tr>
    <?php endforeach; ?>

    Any help appreciated.

    /F

The topic ‘Echo/Show latest post error message’ is closed to new replies.