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 ( example ).
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:
/**
* Create Archive Layout
* @author Bill Erickson
* @link http://www.billerickson.net/wordpress-genesis-custom-layout/
*/
function be_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', 'be_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.
<?php
/**
* Custom Loop for Archive Layout
* @author Bill Erickson
* @link http://www.billerickson.net/wordpress-genesis-custom-layout/
*/
function be_archive_layout_loop() {
$site_layout = genesis_site_layout();
if ( 'sidebar-content-archive' == $site_layout ) {
be_archive_loop();
} else {
genesis_standard_loop();
}
}
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'be_archive_layout_loop');
No comments yet