cmdshiftdesign
Member
Posted 4 months ago #
Instead of full article content to display on my search results page, i prefer for just an excerpt of the article to show — BUT my use of the <?php the_excerpt(); ?> tag in the search.php template keeps returning the full post content. :/ Any ideas what I am overlooking?
[code moderated - please use the pastebin]
cmdshiftdesign
Member
Posted 4 months ago #
OK, I figured out my issue and it is that I misunderstood the function of the_excerpt.
I always understood the excerpt to either be the text defined as the excerpt in wordpress OR the first 100 (or whatever) characters in the post. But, looks like I'm wrong. If no text is in the "excerpt" field of a post will the full content just display.
jclark32
Member
Posted 4 months ago #
add this to your functions.php file
it is a filter that will allow you to control the length of your excerpt by returning 20 that is your excerpt length. That number is then passed into your filter allowing you to manipulate the output. Now whenever you call the_excerpt() it will run you filter.
// the code below is from the codex
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
jclark32
Member
Posted 4 months ago #
also make sure you are running the_excerpt() in the loop :)
cmdshiftdesign
Member
Posted 4 months ago #
Thank you! I have that in place in my functions.php file... but i just did a little test -- made a function file with ONLY that and it worked... so looks like it is being interfered with with something else in that file...
the plot thickens...
cmdshiftdesign
Member
Posted 4 months ago #
jclark32
Member
Posted 4 months ago #
that is odd. Did you place that at the end of the functions.php file?