1

I have the following conditional that is only partially working. It DOES correctly display the content or excerpt if they contain data, but the echo statements do not display. I can place the echo '<h3>... or echo '<div>... outside of the conditional (above or below) and they will display fine.

Using Firebug I have verified whether or not they are outputting.

echo outputs nothing:

<?php if (the_content()) : ?>
    <?php echo '<h3 style="font-weight: 300;">CONTENT</h3>'; ?>
    <?php the_content(); ?>
    <?php echo '<div class="fullwidth_bg" style="height: 20px;"></div>'; ?>
<?php elseif (the_excerpt()) : ?>
    <?php echo '<h3 style="font-weight: 300;">EXCERPT</h3>'; ?>
    <?php the_excerpt(); ?>
    <?php echo '<div class="fullwidth_bg" style="height: 20px;"></div>'; ?>
<?php endif; ?>

echo outputs as expected:

<?php echo '<h3 style="font-weight: 300;">CONTENT</h3>'; ?>
<?php if (the_content()) : ?>
    <?php the_content(); ?>
<?php elseif (the_excerpt()) : ?>
    <?php the_excerpt(); ?>
<?php endif; ?>
<?php echo '<div class="fullwidth_bg" style="height: 20px;"></div>'; ?>

Why are the echo statements not outputting inside of the first conditional above?

6
  • 1
    It looks like the_content() and the_excerpt() functions returns false... Commented Mar 13, 2015 at 11:30
  • 1
    Please show us some fiddle code, so that we solve your problem.@ Dark Anavger seems right that your two functions the_content() and the_excerpt() functions returns false. Commented Mar 13, 2015 at 11:35
  • @DarkAnavger But if (the_content()) returns true and displays the page content if it contains data... I mean, how can <?php the_content(); ?>` get executed and pass right by the <h3> without it getting displayed with the echo? Commented Mar 13, 2015 at 11:35
  • @anantkumarsingh Ok, maybe you guys are right - maybe the_content() and/or the_excerpt are displaying on the if lines and not inside the if conditionals. I'll check my conditional logic and comment back. Commented Mar 13, 2015 at 11:38
  • 1
    You are both correct. I should be using something like if (get_the_content() == "")... - a big oversight. My logic was wrong but you both helped me identify it. Please enter an answer and I will mark it correct. :S Commented Mar 13, 2015 at 11:43

1 Answer 1

1

Following problems may occur in your code, please check :-

  1. Two functions of yours the_content() and/or the_excerpt() returns false.
  2. If not then logic under these two function is not correctly working.

Please check both and tell us that your problem solved or not?

Sign up to request clarification or add additional context in comments.

Comments

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.