Reputation: 787
I'm using a function to decide what the length of my articles are (below). The issue is that on my index page, the_content seems to be 'split up' by my <!-- more -->
tags.
For example, my article is 3000 characters long, but my index page only shows 500 characters before the 'Read More' link appears. My function uses the 500 characters as the_content instead of the actual 3000 characters. The length is shown as Short, even though the full articles is considered Long.
However on the full article page, where all 3000 characters are shown, the function works fine.
Now my question is: is there an alternative for the_content that ALWAYS uses the full article instead of what's currently shown on the page?
function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
$length = strlen($content);
if ($length > 2000) {
return 'Long';
} else if ($length > 1000) {
return 'Medium';
} else if ($length < 1000) {
return 'Short';
}
}
Upvotes: 0
Views: 618
Reputation: 2583
Try this:
function wcount($post) {
$length = strlen($post->post_content);
if ($length > 2000) {
return 'Long';
} else if ($length > 1000) {
return 'Medium';
} else if ($length < 1000) {
return 'Short';
}
}
Then call wcount() from within the post loop with something like echo wcount($post);
Upvotes: 1