If you are using wordpress, sometimes you need to show other pages content in another page.
You can use this function in your theme’s function.php file and you can call it anywhere.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php //$id is the page ID you want to get the content function get_post_page_content( $id ) { $the_query = new WP_Query( 'page_id='.$id ); while ( $the_query->have_posts() ) { $the_query->the_post(); // add this if you want to show title if($title == true){ the_title(); } the_content(); } wp_reset_postdata(); } ?> |
You can use the same function as shortcode and use it in any page content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php function get_page_content( $atts ) { $id=$atts['id']; $the_query = new WP_Query( 'page_id='.$id ); while ( $the_query->have_posts() ) { $the_query->the_post(); return get_the_content(); } } add_shortcode( 'riksi_content', 'get_page_content' ); ?> |
use this shortcode on any page:
[riksi_content id=’Your page ID”]