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" /> </div> <?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:
https://www.coastalmainehospice.org/wordpress/welcome-to-coastal-family-hospice-volunteers/but gives me an error here:
https://www.coastalmainehospice.org/wordpress/news-items/Also, it’s less than perfect when the custom field is left empty.
Thanks in advance,
Jim
- The topic ‘Custom Field is header pic, limit to one per page?’ is closed to new replies.