mcography
mcography

Reputation: 1141

How to Determine Where Excerpt Length is Set in Wordpress?

I am working on a site that uses Isotope to arrange blog posts on the blog page and at the bottom of category pages. The problem I am running into is that the excerpts on these posts are way too long. I'd like them to be only one paragraph instead of 4 or 5 (see the problem at the bottom of this page). Another developer set this up and then left the project, and I am having trouble determining where these excerpt lengths are set. This is what the code looks like on the category.php template.

<div class="catfooter">
<div class="wrap">
<div class="clearfix">
<div class="h3 text-white"><?php single_cat_title('Read More About '); ?></div>
<img src="http://www.oakwoodsys.com/wp-content/uploads/light-blue-line.png">
<?php

    echo '<ul id="isotope-container" class="masonry">';

    $catID = get_query_var('cat');

    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;

    $posts_per_page = 4;

    $args = array(
        'post_type'     => array('post', 'oakwood_quote', 'oakwood_whitepaper', 'oakwood_casestudies', 'oakwood_video'),
        'posts_per_page' => $posts_per_page,
        'paged'         => $paged,
        'cat'           => $catID,

    );
    $insights_query = new WP_Query( $args );

    if ( $insights_query->have_posts() ) {


        while ( $insights_query->have_posts() ) {
            $insights_query->the_post();

            output_insight($post);


        }   
    }

    echo '</ul>';

$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $insights_query;



?>
</div>

<?php

$wp_query = $temp_query;

?>
</div>
</div>
</div>
</div>

I tried changing $insights_query->the_post(); to $insights_query->the_excerpt(); but it broke the page. How can I set the excerpt length here?

Upvotes: 0

Views: 433

Answers (1)

Aibrean
Aibrean

Reputation: 6412

You could change the excerpt length in functions.

Example (you can also set specific categories by ID.

function new_excerpt_length($length) {
if(in_category()) {
return 300;
} else {
return 60;
}
}
add_filter('excerpt_length', 'new_excerpt_length');

Also, if you have excerpts on in WordPress, you can use that to provide more control on the amount of text included.

I'd also give this edit a go (include the excerpt here):

( $insights_query->have_posts() ) {
            $insights_query->the_post();
            the_excerpt();
        }   

Not exactly sure where $post is coming from in output_insight($post);. The $insights_query-> shows all the content being passed into, separated by semicolons. In order to accept the manual excerpt, WordPress needs to know where it should go (definition in the theme is required).

Upvotes: 1

Related Questions