WordPress怎么将一个页面嵌入另一页面?

沃德普拉斯 发布于 3年前 分类:WordPress

我创建了两个单独的页面 testOne 和 testTwo,其中包含一些 UI 设计。还有一页是 pageThree,我需要在其中集成这两个页面。

我是 WordPress 的新手,并尝试为两个页面(testOne 和 testTwo)实现 shortCode,但没有达到结果。

请教教我!

1个回复

  • ttt5

    根据您主题的页面代码,它可能就像在页面内容结束之前挂钩某些操作一样简单(或者只是将代码直接放入带有一些 [条件标签][1] 的页面代码中。

    我能想到的最简单的方法是这样的:

    <?php 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 -->