Support » Themes and Templates » Custom Field is header pic, limit to one per page?

  • I’m doing a CMS WP site and want each page to be able to have a different picture in the header.

    I’ve added a custom field called picture and this code to the header:

    <?php if (have_posts()) : while (have_posts()) : the_post();
    		$picturevalues = get_post_custom_values('picture');
      		foreach ( $picturevalues as $key => $value ) {
             	<div class="picture">
    				<img src="<?php echo "$value"; ?>
                	" width="196" height="132" alt="flowers" />
    		<?php }?>
    <?php endwhile; endif; ?>

    This works fine UNLESS the page has more than one post (like the news page).

    That is: when the page is a PAGE, (with no blog or other posts on it) it’s fine. But having other posts (even without the custom field called “picture”) it breaks.

    It works fine here:

    but gives me an error here:

    Also, it’s less than perfect when the custom field is left empty.

    Thanks in advance,

  • The topic ‘Custom Field is header pic, limit to one per page?’ is closed to new replies.