I am trying to show posts in my home page of my theme where i want to restrict the post content to be displayed as only 20 words. I can use get_content to get the content value but how can i restrict it to show only 20 words. Is there something i can do in my theme to have this restriction on displaying only in the home page
Thanks
Prady
what you want to do is conditionally use excerpts. First you have to edit the excerpt length, Add this to your functions.php file:
If you want to change the text that it appends on the end, or remove it add this directly under the above:
Then, if your homepage is your blog page, add the following to index.php, otherwise add it to page.php or which ever template you’re using for the page in question, instead of
<?php the_content(); ?>
:This should do the trick and uses WordPress’s built-it functionality.
I suggest trawling the WordPress codex, here, it’s full of helpful goodies in regards to content manipulation.
Just use str_word_count function