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 Answer 1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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