Skip to content

Instantly share code, notes, and snippets.

@generatepress
Last active March 15, 2018 15:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save generatepress/2fc35877f91e54fe415eb34a4ddb452c to your computer and use it in GitHub Desktop.
Save generatepress/2fc35877f91e54fe415eb34a4ddb452c to your computer and use it in GitHub Desktop.
Different right sidebar for pages.
<?php
/**
* The Sidebar containing the main widget areas.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// If the navigation is set in the sidebar, set variable to true.
$navigation_active = ( 'nav-right-sidebar' == generate_get_navigation_location() ) ? true : false;
// If the secondary navigation is set in the sidebar, set variable to true.
if ( function_exists( 'generate_secondary_nav_get_defaults' ) ) {
$secondary_nav = wp_parse_args(
get_option( 'generate_secondary_nav_settings', array() ),
generate_secondary_nav_get_defaults()
);
if ( 'secondary-nav-right-sidebar' == $secondary_nav['secondary_nav_position_setting'] ) {
$navigation_active = true;
}
}
?>
<div id="right-sidebar" itemtype="http://schema.org/WPSideBar" itemscope="itemscope" role="complementary" <?php generate_right_sidebar_class(); ?>>
<div class="inside-right-sidebar">
<?php
/**
* generate_before_right_sidebar_content hook.
*
* @since 0.1
*/
do_action( 'generate_before_right_sidebar_content' );
if ( is_singular( 'page' ) ) {
dynamic_sidebar( 'page_sidebar' );
} else {
if ( ! dynamic_sidebar( 'sidebar-1' ) ) :
if ( false == $navigation_active ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h2 class="widget-title"><?php esc_html_e( 'Archives', 'generatepress' ); ?></h2>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<?php endif;
endif;
}
/**
* generate_after_right_sidebar_content hook.
*
* @since 0.1
*/
do_action( 'generate_after_right_sidebar_content' );
?>
</div><!-- .inside-right-sidebar -->
</div><!-- #secondary -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment