Using custom fields to display specific posts
-
I am trying to create a ‘featured post’ section where anchored at the top of the homepage, 3 articles are displayed (thumbnail icon is displayed)
In my post I have created a custom field called ‘post-icon’ and given it a value of a an image url.
I have the below code – which is great for showing the 3 most recent articles, but what I want to do is:
1. check to see if the article has the post-icon custom field and a value for it.
2. if so, display it in the featured section. If not, don’t display it.<?php query_posts('showposts=3&offset=0'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> <img src="<?php echo get_post_meta($post->ID, 'post-icon', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" /> </a> <?php endwhile; endif; ?>I’ve tried a number of things but I can’t figure out how to do this.
Any ideas?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Using custom fields to display specific posts’ is closed to new replies.