Created
August 9, 2013 15:26
-
-
Save rfmeier/6194540 to your computer and use it in GitHub Desktop.
Register and display widget area specific for Custom Post Type Archive pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// register the custom post type widget area | |
genesis_register_sidebar( array( | |
'id' => 'cpt-archive-sidebar', | |
'name' => __( 'Custom Post Type Sidebar' ), | |
'description' => __( 'Display this sidebar on your custom post type archive page.' ), | |
) ); | |
add_action( 'genesis_before_sidebar_widget_area', 'cpt_genesis_before_sidebar_widget_area' ); | |
/** | |
* Callback for Genesis 'genesis_before_sidebar_widget_area' action. | |
* | |
* If on custom post type archive page, remove default sidebar (widget area). | |
* | |
* @author Ryan Meier http://www.rfmeier.net/ | |
* @package Genesis | |
* @category Widget Area | |
*/ | |
function cpt_genesis_before_sidebar_widget_area(){ | |
// if not on custom post type archive page, return | |
if( is_post_type_archive( 'custom_post_type' ) ){ | |
// remove default widget areas if on post type archive pages | |
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); | |
} | |
} | |
add_action( 'genesis_sidebar', 'cpt_genesis_sidebar' ); | |
/** | |
* Callback for Genesis 'genesis_sidebar' action. | |
* | |
* If on custom post type archive page, display cpt widget area | |
* | |
* @author Ryan Meier http://www.rfmeier.net/ | |
* @package Genesis | |
* @category Widget Area | |
*/ | |
function cpt_genesis_sidebar(){ | |
// if not on custom post type archive page, return | |
if( ! is_post_type_archive( 'custom_post_type' ) ) | |
return; | |
// display the post type archive widget area | |
genesis_widget_area( 'cpt-archive-sidebar' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment