编辑
为了将一个页面的内容放入另一个页面,请使用以下函数:
function show_post($path){
$post = get_page_by_path($path);
$content = apply_filters('the_content', $post->post_content);
echo $content;
}
然后为“我们的公司”页面创建一个模板(如template-our_company.php
),您将在其中调用函数(例如<?php show_post('careers'); /* Shows the content of the "Careers" page using the slug. */ ?>
)。
所以模板文件应该包括这样的内容:
<?php
show_post('careers');
show_post('jobs');
show_post('team');
?>
对于您的第二个问题,您需要像这样调整 template-our_company.php 文件:
<?php
<div id="careers"></div>
show_post('careers');
<div id="jobs"></div>
show_post('jobs');
<div id="team"></div>
show_post('team');
?>
然后在菜单仪表板中,只需将导航链接调整为“/our-company/#careers”等内容。
编辑 2
为了在另一个模板中检索具有指定模板的页面内容,您可以执行以下操作: 创建模板(文件 careers.php 和 jobs.php)以及将使用这些模板的帖子
/*
Template Name: Careers
*/
...
/*
Template Name: Jobs
*/
然后在“父”模板中,可以查询上面指定模板选择了
未测试代码的帖子
$args = array(
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_wp_page_template',
'value' => 'careers.php',
'compare' => '='
),
array(
'key' => '_wp_page_template',
'value' => 'jobs.php',
'compare' => '='
)
)
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
the_content();
// or add anything else
endforeach;
wp_reset_postdata();