0

For some reason I can't get my if-statement to echo out the HTML.

<?php
    $my_description = meta('description');
    if (!empty($my_description)): echo '<p class="description">'.$my_description.'</p>';
    echo '<br>'; ?>
<?php endif; ?>

It only outputs the text, nothing else.

meta('description') is from a plugin in Wordpress that should output the text I placed in the backend. The above code ONLY outputs the following: Lorem Ipsum...

Update: I would like it to output: <p class="description">Lorem Ipsum...</p>

4

2 回答 2

2

After a discussion in chat, we discovered that the meta() function was not returning the value we expect. The correct function is get_post_meta

<?php
    $my_description = get_post_meta(get_the_ID(), 'description', 1);
    if (!empty($my_description)):
?>
    <p class="description"><?php echo $my_description; ?></p>
    <br>
<?php endif; ?>
于 2012-11-29T05:16:06.997 回答
0

Ugh... sooo ugly, just do it like this:

<?php
echo !empty($my_description) ? '<p class="description">'.$my_description.'</p>' : '<br />';
?>

Use the ternary operator, don't use that messy if formatting...

于 2012-11-29T05:14:48.083 回答