Wordpress: include content of one page in another

后端 未结 8 1366
挽巷
挽巷 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.

提交回复
热议问题