Include Content From One Page Within Another Page – Genesis Framework

NOTE: The following information is valid for Genesis 1.9.x. Once Genesis 2.0 is released, change the text “genesis_after_post_content” to “genesis_entry_content” in the Include Page template code below. This site in running Genesis 2.0 Beta.

Following is a WordPress page template I created with input from other Genesis Framework professionals. It allows you to include content from one page into another page. The included content is displayed below any original content. This is very useful when you have content that needs to be shared amongst numerous pages. Edit the shared content on one page and all pages including that content will be updated accordingly.

Create the Page Template

Create a file named “include-page.php” and paste in the code below.

<?php
/*  Template Name: Include Page */ 

add_action('genesis_after_post_content', 'include_page');

function include_page() {
	
        $page_id = genesis_get_custom_field('includepage');
        $page_data = get_page( $page_id );
        $title = $page_data->post_title;
        $content = apply_filters('the_content', $page_data->post_content);
		echo '<h1 class="entry-title">'.$title.'</h1>';
		echo '<div class="entry-content">'.$content.'</div>';
        
}

genesis();

Place this new page template file in the root of the child theme folder.

Add New Pages

Add a new page named “Shared Page“. Enter the shared content into this page. Make note of the “Page ID” WordPress assigns to this page.

Add a new page named “Combined Page”. On this page select the “Include Page” template in the pull down menu within the Page Attributes box. Create a custom field named “includepage” and enter the Page ID of the page you wish to include into the value field. Click the Update button.

The “Combined Page” should now display any content you have entered plus include content from the “Shared Page” below it.

The page names I used are for demonstration purposes. You can use whatever page names you prefer. You may choose to assign a <h2> tag and a different class to the title in the page template above since it may not be the best practice to have two page titles with a <h1> tag in the same page.

Include Page Content Without Title

If you prefer not to display the title of the included page, the page template would look like this:

<?php
/*  Template Name: Include Page */ 

add_action('genesis_after_post_content', 'include_page');

function include_page() {
	
        $page_id = genesis_get_custom_field('includepage');
        $page_data = get_page( $page_id );
        $content = apply_filters('the_content', $page_data->post_content);
		echo '<div class="entry-content">'.$content.'</div>';
        
}

genesis();

CSS Buttons for Genesis

Brian Gardner published a post on adding CSS buttons to a website created with the Genesis Theme Framework. According to his post, StudioPress will be implementing these additions in the new Genesis parent theme once Genesis 1.9 is released.

I’ve added a few extra touches to his code which produces what you see below:

Blue Button Link

Gray Button Link

Green Button Link

Purple Button Link

Red Button Link

Yellow Button Link

Following are the changes I made to Brian’s existing style sheet code

.button-blue,
.button-gray,
.button-green,
.button-purple,
.button-red,
.button-yellow {
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    background: url(images/overlay.png) repeat-x;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    color: #444!important;
    font-weight: 400;
    padding: 10px 15px;
    text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.5);
}

In the code above I used a transparent png with a gradient to give the buttons some dimension. You can grab the overlay.png file here.