Combining custom fields and featured images
-
Some of my posts are using the featured images of WordPress, others are using custom fields (the data of the field looks like
<img src="FILELOCATION" class="NAME" alt="TEXT" title="TEXT" width="520" height="250" />
). This has to do with several reasons like old posts, new posts, importing etcetera.I have problems with combining those two. I want WordPress to show the data of the custom field if it exists, or else to show the featured image (or vice versa). Both codes works correctly if they are completely seperated from each other, but I keep getting errors when I try to combine them.
Codes:
<?php echo '<a href="', get_permalink(), '">'; if (has_post_thumbnail()) { the_post_thumbnail('NAME'); } else { echo '<img src="', get_bloginfo('template_directory'), '/images/logo.png', '" width="520" height="250" alt="logo" />'; } echo '</a>'; ?>
and
<?php echo '<a href="', get_permalink(), '">'; $key="NAME"; echo get_post_meta($post->ID, $key, true); echo '</a>'; ?>
Any tips or suggestions?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Combining custom fields and featured images’ is closed to new replies.