Adding this PHP code to your wordpress theme will let you display the post excerpt outside of the loop.
<?php
global $post;
if (is_single()) {
echo get_the_excerpt($post->ID);
}
?>
Adding this PHP code to your wordpress theme will let you display the post excerpt outside of the loop.
<?php
global $post;
if (is_single()) {
echo get_the_excerpt($post->ID);
}
?>
EDITORIAL NOTE: Opinions expressed here are author’s alone, not those of any hosting company, plugin provider, theme company, Syed Balkhi or WordPress Foundation, and have not been reviewed, approved or otherwise endorsed by any of these entities.
DISCLAIMER: We make great efforts to maintain reliable data on all offers presented. However, this data is provided without warranty. Users should always check the provider’s official website for current terms and details. The product offers that appear on the website are from respective hosting companies, plugin companies, and theme companies from which IsItWP receives compensation. This compensation may impact how and where products appear on this site (including, for example, the order in which they appear). This site does not include all WordPress products or all available product offers.
I’m not sure, how do I use this and can it be used on wordpress pages?
Hi Laurize, Lets say you wanted to display the excerpt of a post but within the footer of the page. Normally you would need to have the_excerpt within the loop this would let you place it in any location including the side bar footer etc.
That’s what I need. but how do I use it? do i just replace the ‘ID’?
Nope it will get the ID of the post it is displayed on so just place it within the sidebar or the header footer etc.
I wish it were that simple — it would be wonderful! Sadly, the usage of get_the_excerpt() with a parameter has been deprecated: look at http://core.trac.wordpress.org/browser/tags/3.2/wp-includes/post-template.php line 261 and following.
The Codex also flags this usage as deprecated.
This doesn’t work.
Just tested the snippet to make sure I had no errors and it works fine. Can you give me some details on the what you are doing with the snippet ?