how to show excerpt instead of subtitle in cloud single posts

Posted in: Newspaper
Post count: 19

Hello

Any general help is appreciated
I want to alter a single post template and replace the subtitle with an excerpt.

I can find the shortcode in the cloud library plugin here: https://www.screencast.com/t/H2M9byRoxr
Can you please help show the excerpt instead of subtitle

Thanks in advance

  • This topic was modified 7 years by biznizat. Reason: correct grammer
Post count: 23312

Hi,

If you want to make these changes to the template, you need to create a new excerpt function by post ID which sohuld have to look like this ->

function get_excerpt_by_id($post_id){
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = ($the_post ? $the_post->post_content : null); //Gets post_content to be used as a basis for the excerpt
$excerpt_length = 50; //Sets excerpt length by word count
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);

if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '…');
$the_excerpt = implode(' ', $words);
endif;

return $the_excerpt;
}

And then, below this function, you sohuld to call that by the post ID, like this -> https://www.screencast.com/t/O9XL3PdnzJz7 and the result sohuld look like this -> https://www.screencast.com/t/2Jy1nWjLSiwH

Hope this helps!

Thanks for your understanding!

Post count: 19

Well , thousand words can tell you how much i appreciate your help
i am sure this will help other too

Thank you again Catalin
big thumb up

Post count: 19

i would add also for others , if you don’t want to show excerpt that is taken from content automatically first , but rather the excerpt that you enter manually then using following following function might help :


function get_excerpt_by_id($post_id){
global $post;
$save_post = $post;
$post = get_post($post_id);
$output = get_the_excerpt();
$post = $save_post;
return $output;
}

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.