Related Pages Code Snippet for WordPress

I’m currently working on getting the documentation together for our API (with Fresh Vine) and I needed a bit of code to place in the sidebar that would display any resources from the same family.

Within WordPress I have the pages all nicely nested. So there is a top-level page with a slug ‘api’ (page ID 16), and that has a child slugged ‘documentation’ (page ID 20). This related pages script will check for the children of ‘documentation’ including the first level which we add in at the beginning there.

The page hierarchy looks like: api-> documentation->members->view-id (for example)

The Code

php $Page = get_post();		// Get the Current Page
$ParentID = $Page->post_parent;	// Get the Parent Page ID
if( $ParentID == 16 )
	$ParentID = NULL;	// We're a child of
else if( $ParentID == 20 )
	$ParentID = $Page->ID;	// We 

$Related = get_pages( array(
					    'child_of' => $ParentID,
					    'sort_order' => 'ASC',
					    'sort_column' => 'post_title',
					    'hierarchical' => 0,
						'parent' => -1,
						'post_type' => 'page',
						'post_status' => 'publish' ) );
// Look to see if there are any related pages.
if( !is_null( $ParentID ) ){

	// Get the Parent Page
	$Parent = get_page( $ParentID );	?>
	 post_title; ?>>

post_content ) // Check for empty page
				continue;	?>
		 post_title; ?>

Final Thoughts

All in all the code works splendidly. Though I have taken out all of my styling for this example I have it setup to display the method and to give visual indicators of what page the user is currently on (with a simple if $rPage->ID == $Page-ID check).

Well I hope this was helpful for someone else out there in the inter-webs. If you used the code leave a note so I can see how you used it!

Newish WP Theme: Cotolance

This theme is actually several months old and has been around the block a bit by this point. It is called Cotolance (Coo-toe-lance) and was developed for the company blog of Nineteen05, my web development company. This blog serves as a way for me to share what is coming up on a decade of web development, marketing, management, and community development experience with the Church as a whole. The latter three of these topics are sorely excluded from the seminal educations professional ministers receive during their masters programs (I’m also currently enrolled at Bethel Seminary in St. Paul, MN)

The design heavily borrows from the main Nineteen05.com website (which was completed by Ned Wright last spring) The main differences are in the layout of the content section of the design, and the sidebar. While the nineteen05.com site is fairly monochromatic for the moment, I wanted to bring more color into the blog and did that through the header and the date boxes. The design will likely mimic that of the company site as it goes through renovations in the future.

Cotolance Theme for Nineteen05 Blog

Check out the theme in action

Like the Inductaloot theme, this one is also private. If you are looking for a blog of your own check out Insights For Church and get blogging today! It is hosting the official nineteen05 blog, and hopes to host hundreds of blogs for those involved in ministry in the near future.

New WP Theme: Inductaloot

I’ve launched a blogging community for the church as a whole over at www.insightsforchurch.com and just finished setting everything up yesterday. In the setup process I created a theme for the main WP site and called it inductaloot. After installing several plug-ins and modifying some scripts it seems to be working the way I want it to. Showing the most recent site-wide posts, have a list of the most active blogs (views/comments/posts) on the right, and also will have a site-wide tag cloud as new posts are added (didn’t work retroactively for the 50ish posts already in there).

Insights for Church theme: inductaloot

This theme is a private theme developed for a multi user install of word press. If you are looking for a free blog and are in the ministry at some level (lay or professional) get one! Head over to Insights For Church and sign up for your free blog today.