【问题标题】:Embed one page in another page将一个页面嵌入另一个页面
【发布时间】:2021-09-10 18:51:09
【问题描述】:
我创建了两个单独的页面testOne 和testTwo,其中包含一些 UI 设计。还有一页是pageThree,我需要在其中整合这两个页面。
我是 WordPress 新手,尝试为两个页面(testOne 和 testTwo)实现短代码,但没有达到结果。
请指导我。
【问题讨论】:
标签:
wordpress
wordpress-theming
custom-wordpress-pages
wordpress-rest-api
wordpress-shortcode
【解决方案1】:
根据您的主题的页面代码,它可能就像在页面内容结束之前挂钩一些操作一样简单(或者只是将代码直接放入带有一些[条件标签][1]的页面代码中。
我能想到的最简单的方法是这样做:
get_header(); ?>
<section id="primary" class="content-area col-sm-12 col-lg-8">
<div id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
if (is_page($pageThreePostId)){
// Get the other pages
$testOne = get_post($testOnePagePostId);
if (!empty($testOne) && is_a($testOne,WP_Post::class)){
echo apply_filters('the_content',$testOne->post_content);
}
$testTwo = get_post($testTwoPagePostId);
if (!empty($testTwo) && is_a($testTwo,WP_Post::class)){
echo apply_filters('the_content',$testTwo->post_content);
}
}
?>
</div><!-- #main -->
</section><!-- #primary -->