Custom Layout Options in Genesis

Wordpress PHP net

Genesis comes with a great feature called Layout Options. This allows content creators to specify the layout of the specific page or post they’re writing. By default it comes with all the different ways you can display one, two, or three columns.

You can unregister the defaults, and you can create your own layout options.

I used this on a recent project to create an Archives layout option. When this is selected, the page content is replaced with a thumbnail and excerpt of three children pages.

There’s two steps: register the layout, then use it in your theme.

Register A New Layout

Here’s what I used to create a layout called Sidebar/Content Archive. Place this in your functions.php file:

<?php
// Create Archive Layout
function dh_create_archive_layout() {
genesis_register_layout( ‘sidebar-content-archive’, array(
‘label’ => __(‘Sidebar/Content Archive’, ‘genesis’),
‘img’ => get_bloginfo(‘stylesheet_directory’) . ‘/images/layout-sidebar-content-archive.gif’
) );
}
add_action( ‘init’, ‘dh_create_archive_layout’ );

The first parameter is the layout slug, and the second parameter is an array that contains the label and the image.

Implementation

To figure out what layout a current page is using, use this function: genesis_site_layout();

Once you’ve registered a new layout, you need to decide what you’re going to do with it. In my case, I wanted the Sidebar/Content Archive layout to replace the loop with a listing of children pages. So, I removed the default loop and created a custom one that checked the page layout.