Wordpress: include content of one page in another

后端 未结 8 1254
挽巷
挽巷 2020-12-23 23:18

How do I include the page content of one or more page in another page?

ex. I have pageA, pageB and pa

8条回答
  •  一生所求
    2020-12-23 23:27

    I found this answer posted on the Wordpress forums. You add a little code to functions.php and then just use a shortcode whenever you like.

    function get_post_page_content( $atts ) {
            extract( shortcode_atts( array(
                'id' => null,
                'title' => false,
            ), $atts ) );
    
            $the_query = new WP_Query( 'page_id='.$id );
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                    if($title == true){
                    the_title();
                    }
                    the_content();
            }
            wp_reset_postdata();
    
        }
        add_shortcode( 'my_content', 'get_post_page_content' );
    

    For the shortcode,

    [my_content id="Enter your page id number" title=Set this to true if you want to show title /]
    

提交回复
热议问题