1

I'm trying to create a query that

IF there is a value in the 'FeaturedQuote' custom field, then this shows

<h3 class="featuredquote"><blockquote><span class="bqstart">&#8220;</span><?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'FeaturedQuote', true);
    wp_reset_query();
    ?>
<span class="bqend">&#8221;</span></blockquote>
</h3>

IF NOT, this shows:

<img src="<?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'InsertFullImg', true);
    wp_reset_query();
    ?>">

I cant get it right!

Thanks

1

Assign the return value of the first check to a variable, and test if there is something in it:

if ( $quote = get_post_meta( get_the_ID(), 'FeaturedQuote', TRUE ) )
{
?><h3 class="featuredquote"><?php the_title(); ?></h3>
<blockquote><span class="bqstart">&#8220;</span><?php
    echo $quote;
    ?>
<span class="bqend">&#8221;</span></blockquote>
<?php
}
elseif ( $img = get_post_meta( get_the_ID(), 'InsertFullImg', TRUE ) )
{
    echo "<img src='$img' alt=''>";
}

Note, a <h3> cannot be the parent of a <blockquote>. Headlines can contain inline elements only.

  • Thanks. This works but returns the img url for the image. How can I place in <img> tags? – emailsforben May 5 '13 at 10:26
  • @emailsforben See my update. – fuxia May 5 '13 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.