Filipe Manuel
Filipe Manuel

Reputation: 995

Add a page to another page

Well guys, I was wondering how can I add a page to another.

Example: The "Contact Us" of my company will be based on the page "Service" from that bank (Example).

I wonder how I can create a separate page in the format of the example image (contact-content.php) and include in page.php, but with the condition if and only if it is the page "Contact Us".

I started writing the code but could not finish it:

This is my page.php

<?php get_header();?><!--AQUI FICA O HEADER-->



    <div id="content"><!--INICIO DIV CONTENT-->


        <div id="page_content"><!--INICIO DIV PAGE_CONTENT-->

            <?php if (have_posts()): while (have_posts()) : the_post();?>


                <span class="titulo"><?php the_title();?></span>
                <?php the_content();?>


            <?php endwhile; else:?>
            <?php endif;?>

        </div><!--FIM DIV SINGLE_CONTENT-->


    </div><!--FIM DIV CONTENT-->

I hope that you'd understand, now, Thank you.

Upvotes: 0

Views: 316

Answers (1)

Inigo
Inigo

Reputation: 64

Try with a shortcode.

Paste this code to your functions.php:

function my_show_page( $atts ) {
    extract( shortcode_atts( array( 'page_id' => 0 ), $atts ) );
    $page = get_page( $page_id );
    return apply_filters( 'the_content', $page->post_content );
}

add_shortcode( 'my_show_page', 'my_show_page' );

And now, in any page or post, you can write:

[my_show_page page_id="999"]

999 is the id of the page to display.

Upvotes: 1

Related Questions