Reputation: 35
I need to use the wp_trim_words()
function, along with a "read more" text that when clicked shows the rest of the content just underneath, like a toggle.
Is this possible?
Upvotes: 2
Views: 10009
Reputation: 3008
Try this
<?php
echo wp_trim_words(get_the_content(), 40, '...');
?>
Or
<?php
echo wp_trim_words(get_the_content(), 40, 'Read More');
?>
Or
<?php
echo wp_trim_words(get_the_content(), 40, 'See More');
?>
For tuggle you need to use javascript or jquery. When you will use jquery/script, no need to use wp_trim_words function just use some text with ancher tag(control) and hide/show some content on click.
Upvotes: 1
Reputation: 807
To display page content you might be using the_content() or echo get_the_content(). But instead you just use below line
echo wp_trim_words(get_the_content(), $string_length, $text_read_more_optional); //example, $string_length=50, $text_read_more_optinal='Read More'
So, i guess your code would look something like this:
if(have_posts()){
while(have_posts()){
the_post();
the_title(); //display title
echo wp_trim_words(get_the_content(), 100, 'Read More'); //display content
}
}
Upvotes: 0