根据@EAMann的回答,我假设您希望“Extracts Showreel”是可变的,并基于传递变量返回内容?
function mytheme_get_page_content_by_title( $title = false ) {
if ( false == $title ) return;
$page = get_page_by_title( $title );
$my_id = $page;
$post_id = get_post($my_id, ARRAY_A);
$title = $post_id[\'post_title\'];
$content = $post_id[\'post_content\'];
return $content;
}
然后在模板中:
echo mytheme_get_page_content_by_title( \'Excerpts Showreel\' );
请注意,您可能需要对
$title
正在传递到函数中的变量。
EDIT
我不知道您为什么需要返回标题(这是您开始的内容,并传递给您的函数),但现在您可以:
function mytheme_get_page_details_by_title( $title = false ) {
if ( false == $title ) return;
$page = get_page_by_title( $title );
$my_id = $page;
$post_id = get_post($my_id, ARRAY_A);
$posttitle = $post_id[\'post_title\'];
$postcontent = $post_id[\'post_content\'];
$details = array(
\'title\' => $posttitle,
\'content\' => $postcontent
);
return $details;
}
然后,您必须将其传递给变量才能在模板中使用它:
$mypostdetails = mytheme_get_page_details_by_title( \'Excerpts Showreel\' );
echo $mypostdetails[\'title\']; // print the post title
echo $mypostdetails[\'content\']; // print the post content