The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Custom Field is header pic, limit to one per page? (1 post)

  1. jimmerd
    Posted 7 years ago #

    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,

Topic Closed

This topic has been closed to new replies.

About this Topic