I have many pages in my wp installation. All I want is to be able to display the excerpt of any page, also on any page (before more tag). How do I go about it?
I was fetching the content of the current (front) page through this code:
global $more;
$temp = $more;
$more = false;
echo get_the_content( '' );
$more = $temp;
(I use these lines in my front page template)
But I have no idea of how do I fetch the content of any page. Maybe I need to do manipulations with add~/remove_filter changing the page id/slug/title/etc?
The content is manipulated by the
get_the_content
function, and that function always assumes the current post in the Loop. You can’t pass it an ID, strangely.The easiest way to get just the bit before the more for an arbitrary post ID is:
There may be ways to hijack the
global
$post
variable but unless you really need the complex manipulation ofget_the_content
I wouldn’t bother. You can always create a near clone of that function that will allow you to pass an ID into it.Another way to get the excerpt, by that I mean the text before the
<!--more-->
tag, is to use the following function:get_extended()
As it says in the WordPress codex: