WordPress.org

Forums

Ok, I'm Stumped (3 posts)

  1. Amulet
    Member
    Posted 11 years ago #

    I have the following code in two themes:

    <?php
    foreach ($recentposts as $post) {
    if ($post->post_title == '')
    $post->post_title = sprintf(__('Post #%s'), $post->ID);
    echo "<li><a href='?p=$post->ID'>";
    the_title();
    echo '</a></li>';
    }
    ?>

    It works in one theme, but in the other, I get this error:

    Warning: Invalid argument supplied for foreach() in /home/myusername/public_html/wp-content/themes/minim8/sidebar.php on line 18

    The code is exactly the same for both. Whassup wif dat? Help appreciated and may result in good karma for you.

  2. Kafkaesqui

    Posted 11 years ago #

    Where is $recentposts set? It's not a WP variable available to the templates, so a bit of (custom) code must be assigning something to it, possibly in the template of the theme where the code works.

  3. Amulet
    Member
    Posted 11 years ago #

    Oh...after you explained that, it occurred to me to look for more code in the theme I copied that from...and I found it. It's working now. Thanks. *blush!*

Topic Closed

This topic has been closed to new replies.

About this Topic