• Resolved benember

    (@benember)


    I’ve just inherited a wordpress site (v4.1) and I’m trying to perform the simple task of showing a single blog post from a specific category on the home page. This is my code:

    <?php
    	query_posts(array('category_name' => 'people'));
    	$i = 1;
    	if ( have_posts() ) while( have_posts() && $i < 2 ) : the_post();
    ?>
    
    	<?php the_excerpt(); ?>
    
    <?php $i++; endwhile; ?>

    And it brings back nothing, if I put in <?php the_content(); ?> I get the full content of the post.

    Is there something wrong with my loop, or somewhere else in wordpress I should be looking at to get the_excerpt() working?

    Elsewhere in the theme I see this code:

    <?php echo apply_filters( 'the_content', apply_filters('the_excerpt', get_the_excerpt() ) ); ?>
    
    <?php the_content(); ?>

    When I try that in my loop it also just brings back the whole content of the post.

    If someone could point me in the right direction I would be very grateful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • DivByZRo

    (@divbyzro)

    Hi,

    I would suggest you have a closer look at the code for the ‘the_excerpt’ filter. Maybe comment it out and see what happens. Also check out this link where they discuss a problem very similar to yours:

    Thread Starter benember

    (@benember)

    I couldn’t find any filters relating to the excerpt but assumed that a ‘the_content’ filter was causing the problem. So I created an excerpt filter to generate the excerpt from the post content and that seems to have done it:

    add_filter( 'the_excerpt', 'custom_the_excerpt');
    
    function custom_the_excerpt( $content )
    {
    	$trimmed = wp_trim_words( $content, 30, '&hellip;' );
    	return $trimmed;
    }

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the_content works but the_excerpt doesn't’ is closed to new replies.