1

I'm using the following code to show the single most recent post on my landing page:

<?php if (have_posts()) : ?>
<?php if (($wp_query->post_count) > 1) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_excerpt() ?>
<?php endwhile; ?>

<?php else : ?>

<?php while (have_posts()) : the_post(); ?>
<?php the_excerpt() ?>
<?php endwhile; ?>
<?php endif; ?>

<?php else : ?>
<p>Nothing to see here.</p>

<?php endif; ?>

My problem is the code doesn't seem to be producing an excerpt. What could be the problem?

4
  • the page itself dont have text - growingedgecoaching.com/home how could wordpress generate the excerpt from that? Have you added text in editor while doing post ?
    – Amit Kosti
    Jul 30, 2012 at 23:20
  • I've corrected the link to the correct page- growingedgecoaching.com/blog The problem persists. Jul 31, 2012 at 0:38
  • Why do you close and re-open the PHP context on each line? That’s not necessary.
    – fuxia
    Jul 31, 2012 at 6:04
  • solved? right now, the link /blog/ shows thumbnails and excerpts; if not solved, please paste the full code of the template into a pastebin
    – Michael
    Jul 31, 2012 at 11:45

1 Answer 1

2
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt() ?>
<?php endwhile; else: ?>
    <p>Nothing to see here.</p>
<?php endif; ?>

This is the right syntax to show title and the excerpt on home page.

2
  • Amit, thank you again for the help. We are getting closer to being correct. If you visit the site now, it simply links to "Landing," instead of displaying post excerpts. Any ideas on why that may be? Jul 31, 2012 at 0:37
  • I found the excerpt of first post is showing up on landing page, but the title and link is different.. please, provide us the full code of your landing page using pastebin.com
    – Amit Kosti
    Aug 1, 2012 at 7:37

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.