billa1
Member
Posted 4 months ago #
I want to limit the length of the_content to display on homepay. I can limit using the get_the_content function, but the problem is that get_the_content does not get the content with formatting (eg. does not include image or paragraph tag etc).
Please help me with it.
use the 'more-tag' when writing or editng your posts.
http://codex.wordpress.org/Customizing_the_Read_More
also, you could apply the 'the_content' filter on the truncated get_the_content()
example:
<?php echo appply_filters('the_content', substr(get_the_content(), 0, 200) ); ?>
http://codex.wordpress.org/Plugin_API/Filter_Reference
You're close to solving it! After you get_the_content() and play with the data, do apply_filters() like so.
$content = get_the_content();
$content = apply_filters('the_content', $content );
Then the shortcodes and formatting will be applied.
Edit: 4 minutes, I'm getting slower. Darn you Sweeper, Daaarrrnnnn yooouuu! :)
Sunny Johal
Member
Posted 4 months ago #
Just do the following to return the content to a variable where you can manipulate it
<?php
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
?>
this will produce the same output that the_content() returns. You can then limit the length using your method without using the 'more-tag'. Hope this helps.
Sunny
billa1
Member
Posted 4 months ago #
@alchymyth and Jan Dembowski Thanks for the quick replies :) Solves my problem.