Forums

error in line <? foreach($postimg as $image) (6 posts)

  1. sbscheema
    Member
    Posted 3 years ago #

    Hi,I am new to programming.

    If you look at the following blog http://outdooractivitiesforkids.com/wordpress/?p=3 I get the following error

    Warning: Invalid argument supplied for foreach() in /home/a6228915/public_html/wordpress/wp-content/themes/positie_1/index.php on line 11

    and LINE 11 in index.php says:

    1. <?php get_header(); ?>
    2.
    3. <?php include(TEMPLATEPATH."/sidebar.php");?>
    4.
    5. <!-- begin content -->
    6. <div id="main">
    7. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    8. <h1><?php the_title(); ?></h1>
    9.
    10. <? $postimg = get_post_meta($post->ID, "pre_image", false); ?>
    11. <? foreach($postimg as $image) {
    12. echo "<img class=\"fullimg\" src=\"".$image."\" />";
    13. } ?>
    .
    .
    .
    .
    .

    Please help how do I fix it. I want pictures in my blog.

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    That would make me think <? $postimg = get_post_meta($post->ID, "pre_image", false); ?> returned nothing.

    add <?php print_r($postimg);?> after that to see what's returned.

  3. MichaelH
    Volunteer
    Posted 3 years ago #

    Also a good habit to use <?php rather than <?.

  4. MichaelH
    Volunteer
    Posted 3 years ago #

    Also, please note I've delete your other thread that mentions this same error.

  5. sbscheema
    Member
    Posted 3 years ago #

    Are you saying insert the line you gave me between line 10 & 11... like this

    10. <? $postimg = get_post_meta($post->ID, "pre_image", false); ?>
    <?php print_r($postimg);?>
    11. <? foreach($postimg as $image) {

    Sorry for double posting ( in threads)

  6. MichaelH
    Volunteer
    Posted 3 years ago #

    Yes. I'm guessing that it will display NOTHING. You do have custom fields with 'pre_image', correct?

    Related:
    Using_Custom_Fields

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags