24 December 2013

WordPress Include Page or Post within another Page or Post via Templates

Add this function to theme's functions.php.
And then make call in ones page.php, single.php, home.php, index.php or custom template file.
You can include on page within another.

//Add this function in theme's functions.php
function show_page($path)
{
    $page = get_page_by_path($path);
    $content = apply_filters('the_content', $page->post_content);
    echo $content;
}
//Call function from your page/post/template file
<?php  show_page('about'); // Display the content of the "About" page. ?>
<?php  show_page('category/postname'); // Display content of a Post page. ?>

No comments:

Post a Comment