How to add a sidebar to the Q&A pages

Seeing as there are no actual pages for the Q&A plugin, how do i assign a sidebar to those pages ?

  • Nithin

    Hi Graeme,

    Hope you are doing good today. :slight_smile:

    how do i assign a sidebar to those pages ?

    It depends upon the theme layout, if you are referring the /questions/ask url, the plugin makes use of the page.php template in a default WordPress theme, to display the content. You can add, the sidebar code in your page.php, this would change depending upon your themes template hierarchy:

    <?php get_sidebar(); ?>

    I hope this is what you are looking for. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Nithin

    Hi Graeme,

    But this will essentially add it to all the pages?

    Yes, this will make changes to all your pages. You could try overriding the ask page by adding the page template page-ask-question.php in your child themes directory. I have written the code based on Twenty Sixteen theme below:

    <?php
    /**
     * The Page for QA Ask
     *
     *
     * @subpackage Twenty_Sixteen
     */
    
    get_header();
    wp_enqueue_style( 'qa-section', QA_PLUGIN_URL . QA_DEFAULT_TEMPLATE_DIR . '/css/general.css', array(), QA_VERSION );
    ?>
    
    <div id="primary" class="content-area">
    	<main id="main" class="site-main" role="main">
    
    		<!-- QA code starts here -->
    		<article class="entry-content qa-menu">
    			<?php the_qa_menu(); ?>
    		</article>
    
    		<header class="entry-header">
    			<h1 class="entry-title">
    				<?php echo __( 'Ask a question', 'twentysixteen' ); ?>
    			</h1>
    		</header>
    
    			<div id="qa-page-wrapper">
    			    <div id="qa-content-wrapper">
    
    			    <?php do_action( 'qa_before_content', 'ask-question' ); ?>
    
    				    <div id="ask-question">
    					    <?php the_question_form(); ?>
    				    </div>
    
    			    <?php do_action( 'qa_after_content', 'ask-question' ); ?>
      			  </div>
    			</div><!--#qa-page-wrapper, QA end-->
    
    	</main><!-- .site-main -->
    
    	<?php get_sidebar( 'content-bottom' ); ?>
    
    </div><!-- .content-area -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    This code is modified based on twentysixteen theme, you'll have to work according to your themes template to get the desired changes. You can hence add the get_sidebar() code to QA page only.

    Please let us know if you need any further help. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.