Need Advice? CALL: +61 417949565

Riksi - web design and development

  • Home
  • ABOUT US
  • OUR WORK
  • BLOG
  • CONTACT US
  • Home
  • BLOG
  • Web developing
  • PHP
  • Show WordPress Page Content in Another Post Template

Show WordPress Page Content in Another Post Template

Show WordPress Page Content in Another Post Template

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.

PHP
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.

PHP
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”]

Tagged under: content
Nick
Tuesday, 02 February 2016 / Published in PHP, Web developing, Wordpress

What you can read next

Migrate WordPress server from Local to Live
Run WordPress shortcode by PHP
Update PHP Memory Limit

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archive

  • General
    • Smart Home
  • Web developing
    • command line
    • CSS
    • General
    • git
    • Javascript
    • Laravel
    • Magento
    • MySQL
    • PHP
    • Security
    • Shopify
    • Wordpress

Recent Posts

  • Install HomeAssistant on Raspberry pi

  • Shopify ERR_INVALID_ARG_TYPE Error

Riksi

Riksi is a creative, professional & cutting-edge custom web design and development company.

HERE TO HELP

  • BLOG
  • Contact Us
  • Our Work
  • About Us

New on Blog

  • Install HomeAssistant on Raspberry pi

    To install it, We need to connect the SD card t...
  • Shopify ERR_INVALID_ARG_TYPE Error

    fix the Internal Server Error occurred while in...

GET IN TOUCH

T: (+61) 417 949 565
Email: [email protected]

Contact Us
Fill out the form and our team will be in touch with you promptly. Thank you for your interest!

AU & NZ
T: (+613) 9014 9495
T: (+61) 417 949 565
Email: [email protected]


US & Canada
Email: [email protected]

NAME

EMAIL

PROJECT TYPE
PROJECT BUDGET

MESSAGE

Could not authenticate you.

Whats on Instagram

Loading...

Tags

.htaccess calculation cherry pick composer content css deployer documentation error flex general knowledge get started git git stash hack javascript log mysql package password php PHP Trick replace scss shopify sidebar ssh symlink sync trick ubuntu windows 10 wordpress trick wp
  • GET SOCIAL
Riksi - web design and development

© 2020 All rights reserved. Riksi.com.

TOP