I want to make sure the sidebar on every page the plugin creates is the same.
I created a custom sidebar called “question-sidebar” and I’m trying the following code, but it’s not working.
// Registering new sidebar for Singular Question Page
genesis_register_sidebar( array(
'id' => 'question-sidebar',
'name' => __( 'Single Question Sidebar'),
'description' => __( 'This is the single question sidebar section.' ),
) );
add_action('get_header','custom_question_sidebar');
function custom_question_sidebar() {
if ( is_singular('dwqa-question') ) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'do_question_sidebar' );
}
}
function do_question_sidebar() {
genesis_widget_area( 'question-sidebar' );
}
I also tried…
// Registering new sidebar for Question Plugin
genesis_register_sidebar( array(
'id' => 'question-sidebar',
'name' => __( 'Question Sidebar'),
'description' => __( 'This is the question sidebar.' ),
) );
add_action('get_header','custom_question_sidebar');
function custom_question_sidebar() {
if ( is_page( array( 128, 129 ) ) || is_singular('dwqa-question') ) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'do_question_sidebar' );
}
}
function do_question_sidebar() {
genesis_widget_area( 'question-sidebar' );
}
What am I doing wrong? How do I get the same sidebar on each page?
Please send me username & password of your site for further checking, I will help you resolve it.
I appreciate the response, but giving you my un/pw is not exactly a solution.
In this case, you can add the following code the functions.php file to create new widget sidebar.
1/ Add the code
function dw_theme_widgets_init() { register_sidebar( array( 'name' => __( 'Q&A Sidebar', 'demo-theme' ), 'id' => 'sidebar-qa', 'description' => 'Add the widgets to show on the question page', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); } add_action( 'widgets_init', 'dw_theme_widgets_init' );
2/ Add the following code to the sidebar.php file in your theme folder.
<?php /** * The sidebar containing the main widget area * * @package WordPress * @subpackage Twenty_Fifteen * @since Twenty Fifteen 1.0 */ $dwqa_options = get_option( 'dwqa_options' ); $dwqa_options = get_option( 'dwqa_options' ); $page_template = false; if ( isset( $dwqa_options['pages']['archive-question'] ) ) { $page_template = get_post_meta( $dwqa_options['pages']['archive-question'], '_wp_page_template', true ); } if ( ( is_tax( 'dwqa-question_category' ) || is_tax( 'dwqa-question_tag' ) || is_post_type_archive( 'dwqa-question' ) || is_post_type_archive( 'dwqa-answer' ) || isset( $wp_query->query_vars['dwqa-question_tag'] ) || isset( $wp_query->query_vars['dwqa-question_category'] ) || is_singular( 'dwqa-question' ) || is_page_template( $page_template ) || is_page( $dwqa_options['pages']['archive-question'] ) ) && ( is_active_sidebar( 'sidebar-qa' ) ) ) : ?> <div id="secondary" class="widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-qa' ); ?> </div> <?php elseif ( is_active_sidebar( 'sidebar-1' ) ) : ?> <div id="secondary" class="widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-1' ); ?> </div> <?php endif; ?>
3/ Create new file with named “sidebar-qa.php” Then add the following code to this file:
<?php ?> <?php if ( is_active_sidebar( 'sidebar-qa' ) ) : ?> <div id="secondary" class="widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar-qa' ); ?> </div> <?php endif; ?>
4/ Go to the Dashboard > Appearance > Widgets and add the widgets to the “Q&A Sidebar”.
Please login or Register to submit your answer