• Roweena

    (@roweena)


    I want to add a latest post list to my WP websites home page (a page not a post) as follows:

    <?php
    $postslist = get_posts(‘numberposts=10&order=ASC&orderby=title’);
    foreach ($postslist as $post) :
    setup_postdata($post);
    ?>
    <div>
    <?php the_date(); ?>

    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    </div>
    <?php endforeach; ?>

    It is clashing with other code I have in the page that loops over a custom field that displays images, the images don’t show if I also add the lates post code. It’s something to do with the ordering of the php as if I add the latest post code AFTER my custom image code everything works ok. Custom image code is as follows:
    <?php
    $image = get_post_meta($post->ID, “image”, true);
    //check that we have a custom field
    if ($image != “”)
    {
    // Separate our comma separated list into an array
    $image = explode(“,”, $image);
    //loop through our new array
    foreach ($image as $picture)
    {
    echo “<img src='” . $picture . “‘ />”;
    }
    }
    ?>

    Help greatly appreciated

The topic ‘Latest posts clashing with custom field code’ is closed to new replies.