0

I am using a custom template homepage in which I want to display some excerpt from a category but it's not displaying as I code for just the_excerpt. I have a confusion too, they say the the_excerpt should be used within loop. What is the main reason of loop? As my code is wrapped within the loop, am i missing something?

  • Code missing a closing semicolon for closing statement in PHP in the first line. Just put a semicolon at the end of the_post();. And endif has a wrong "php" constant before it. Or, it's just a typo! :) – Mayeenul Islam Aug 19 '13 at 11:24
  • @MayeenulIslam sorry i missed semicolon when editing my code here as well as php, i have the semicolon in my code but it doesn't work. – Nofel Aug 19 '13 at 13:04
  • Can you post the whole code of your template file please? – iEmanuele Aug 19 '13 at 13:58
  • @iEmanuele sure, here – Nofel Aug 19 '13 at 14:00
  • your code looks just fine, i've tested it and it works – iEmanuele Aug 19 '13 at 14:05
1

According to your question:

What is the main reason of loop?

the clearest answer comes from official documentation:

The Loop is PHP code used by WordPress to display posts. Using The Loop, WordPress processes each post to be displayed on the current page, and formats it according to how it matches specified criteria within The Loop tags. Any HTML or PHP code in the Loop will be processed on each post.

When WordPress documentation says "This tag must be within The Loop", such as for specific Template Tag or plugins, the tag will be repeated for each post.

It's correct put within the loop the_excerpt() template tag.

For example a loop code it might looks like:

<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
  <p><?php the_excerpt(); ?></p>
<?php endwhile; else: ?>
  <p>No posts were found</p>
<?php endif; ?>

To help you with your issue, it could be a good idea posting the whole code

  • i did. pls have a look. – Nofel Aug 19 '13 at 14:11
  • @AmmarKhan, if you change the template tag from the_excerpt() to the_title() what's happen? – iEmanuele Aug 19 '13 at 14:18
  • the_title shows title but the_excerpt doesn't show excerpt. yes i have excerpt in my backend. – Nofel Aug 19 '13 at 16:41
  • very very strange, have you tried to disable the plugins installed or change the theme? – iEmanuele Aug 19 '13 at 16:59
  • 1
    @AmmarKhan: what if you use the_content() instead of the_excerpt()? Do that work? – Mayeenul Islam Aug 20 '13 at 8:13

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.