전체 워드 프레스 페이지의 내용을 가져 오는 방법이 있습니까? 내 문제는 한 페이지 레이아웃을 만들기 위해 다른 페이지에 페이지 콘텐츠를 포함하고 싶습니다. 내가 시도한 것은 다음과 같습니다.
$post = get_post($the_page_id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
그러나 페이지에는 자체 템플릿이 있으며 template.php 파일에서 수행 된 작업을 포함하여 전체 페이지를 표시하고 싶습니다. 가능합니까?
글쎄, 나는 이것에 대한 해결책을 찾았습니다. 최선의 방법은 아닐 수도 있지만 이것은 나를 위해 일했습니다. 한 페이지 페이지를 나타내는 "홈"페이지를 만들었습니다. 이 페이지의 모든 하위 페이지에는 머리글 또는 바닥 글을 포함하지 않는 특정 템플릿이 있습니다. 내 홈 템플릿은 다음과 같습니다.
//fetch header as usual
get_header();
//fetch all subpages of this page
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'orderby' => 'menu_order', 'order' => 'ASC'));
$children = get_page_children( get_the_ID(), $all_wp_pages );
//browse these subpages and get the content for each one
foreach($children as $child){
$post = get_post($child->ID);
getOnePageContent($post);
}
//footer
get_footer();
이제 functions.php에서 getOnePageContent를 정의했습니다.
function getOnePageContent($page){
global $post;
$post = $page;
$slug = get_page_template_slug( $page->ID );
if($slug){
$pl = get_the_permalink($page);
$content = file_get_contents($pl);
echo $content;
} else {
$content = apply_filters('the_content', $page->post_content);
echo $content;
}
wp_reset_postdata();
}
하위 페이지에 머리글이나 바닥 글이 포함되어 있지 않으면 제대로 작동합니다. 물론 file_get_contents로 페이지를 가져 오는 것이 우아하거나 좋은 해결책이라고 생각하지 않지만 적어도 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다