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
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!
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;
}