I may need to work on the titling of this.
I have a functiontwo functions that affect the_excerpt
:
// Grab First Paragraph Of Text And Ignore Images For Excerpt
function awesome_excerpt($text, $raw_excerpt) {
if( ! $raw_excerpt ) {
$content = apply_filters( 'the_content', get_the_content() );
$text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
}
$text = preg_replace("/<img[^>]+\>/i", "", $text);
return $text;
}
add_filter( 'wp_trim_excerpt', 'awesome_excerpt', 10, 2 );
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
AndNow, on my index.php
, those posts show the first paragraph of the post. I am also trying to show the excerpt when you click into a posts in an area called Related Posts. In Related Posts I want it to show a limit of x characters.
On the index.php
I am leaving it as the_excerpt
, but on my Related Posts I'm calling it with . This is what my HTMLthe markup looks like when I'm calling it for the Related Posts like:
But I don't want the <a>
inside. When I'm calling the_excerpt
on the excerptRelated Posts the <a>
isn't even inside so I'm not sure how it's being wrapped in ainside of the <p>
.
EDIT
I realized I didn't include a crucial function On the main posts in index. After removing it,php it's wrapping the first paragraph from the post into a <p>
disappeared.
// Grab First Paragraph Of Text And Ignore Images For Excerpt
function awesome_excerpt($text, $raw_excerpt) {
if( ! $raw_excerpt ) {
$content = apply_filters( 'the_content', get_the_content() );
$text = substr( $content, 0, strpos( $content, '</p>' ) + 4 );
}
$text = preg_replace("/<img[^>]+\>/i", "", $text);
return $text;
}
add_filter( 'wp_trim_excerpt', 'awesome_excerpt', 10, 2 );
I'm using, this so thatis correct. I would like to do the same for the excerpt on my main blogRelated Posts, but it shouldn't have the (index.php<a>
) inside of it pulls the first paragraph. If it's outside of the article. When youcall why is it being included inside?
If you'd like a live example click on an article youhere to view my blog and click a post to see the Related Posts, this is where I want to limit the character count.