0

I have a WordPress theme with a brief summary, with css styling, at the top of a post. This is wrapped in an if statement to only display if there is a summary.

Using the code below, the summary text displays, but the surrounding HTML markup is not included in the page source.

<?php if (get_smry_text($post)) { ?>
<div class="summaryWrap">
    <div class="sumText">
        <p><?php get_smry_text($post); ?></p>
     </div>
 </div>
 <?php } ?>

Can anyone offer a suggestion as to why this might be?

2 Answers 2

1

It is possible that get_smry_text() doesn't return any values.
Instead it echoes the content directly. If you are using this function you can do something like this:

<?php if ($smry = get_post_meta($post->ID, 'smry_text', true)) { ?>
<div class="summaryWrap">
    <div class="sumText">
        <p><? echo $smry; ?></p>
     </div>
 </div>
 <?php } ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect...and kudos on the homework! If I understand it now, the code within the if statement gets skipped completely, and instead the if condition itself is echoing the text?
0

Try doing this:

<?php
   $smry_text = get_smry_text($post);
   if ($smry_text) {
       $text = '<div class="summaryWrap">
               <div class="sumText">
                 <p> ' . $smry_text .  '</p>
               </div>
           </div>';
        echo $text;
   }
?>

3 Comments

And this does what? It won't even compile now, unfortunately.
Using this the summary text does not display at all :(
Then get_smry_text must not be returning anything

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.