Wordpress: include content of one page in another

后端 未结 8 1256
挽巷
挽巷 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:42

    Kit Johnson's wordpress forum solution with creating a shortcode works, but adds the inserted page in the top of the new page, not where the shortcode was added. Close though, and may work for other people.

    from the wordpress post, I pieced together this which inserts the page where the shortcode is put:

    function get_post_page_content( $atts ) {
        extract( shortcode_atts( array(
            'id' => null,
            'title' => false,
        ), $atts ) );
        $output = "";       
    
        $the_query = new WP_Query( 'page_id='.$id );
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
                if($title == true){
                $output .= get_the_title();
                }
                $output .= get_the_content();
        }
        wp_reset_postdata();
        return $output;
    
    }
    

    Then, the shortcode bit works as expected. If you don't want the title, title=false does not work, you need to leave title off entirely.

    0 讨论(0)
  • 2020-12-23 23:45

    You could install a Plugin "Improved Include Page". Once installed, you create page X and enter:

    [include-page id="123"]
    [include-page id="124"]
    [include-page id="125"]
    

    where these are the ID's of pages A, B and C respectively

    0 讨论(0)
提交回复
热议问题