-2

I need to show a summary of each post in the sidebar. Is there any way to do this?

2
  • Add your summary in the excerpt field, loop through the posts and echo out the excerpt on each post – Vishwa May 15 '19 at 5:20
  • 1
    Please update your question to provide a narrowly scoped problem. Currently, it is not clear which part of the task you have a problem with. – nmr May 15 '19 at 5:29
0

Easy way is use - excerpt() else you can also use wp_trim_words( get_the_content(), 40, '...' );

In a excerpt(), You have to add content on excerpt in backend. While wp_trim_words will trim words from content.

In sidebar case you have to add shortcode into functions.php file which uses in sidebar widget(if you are using widgets).

function test_short(){
    ob_start();
    global $post;
    echo wp_trim_words( get_the_content($post->ID), 40, '...' );
    return ob_get_clean();
}

add_shortcode('test_short', 'test_short');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.