Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
426 views
in Themes by
I have "custom content in home page instead of Q&A".

I want a different sidebar for that page only.....................

 

Can I do this ?
Q2A version: 1.7.1 with Snow Flat 1.4

1 Answer

+1 vote
by

When you talk about sidebar it is just a welcome widget especially. 

To do that do following..

If you have some logic or query for each sidebar than better to create methods for each and call to the sidepanel. However, if you don't have much things and just a string or one line of code than you can directly write withing the conditions (see my code comments)

Note: The sample code is based on SnowFlat current version

<?php
class qa_html_theme extends qa_html_theme_base
{
    
    //...
    
    /**
     * [home_sidebar method for home sidebar]
     * @return [void] [your code return]
     */
    public function home_sidebar() {
        $this->output('Add your code for home sidebar');
    }
    
    /**
     * [q_list_sidebar method for q_list sidebar]
     * @return [void] [your code return]
     */
    public function q_list_sidebar() {
        $this->output('Add your code for q_list sidebar');
    }
    
    /**
     * [q_view_sidebar method for q_view sidebar]
     * @return [void] [your code return]
     */
    public function q_view_sidebar() {
        $this->output('Add your code for q_view sidebar');
    }
    
    /**
     * This is the actual sidepanel in SnowFlat theme
     * @return 
     */
    public function sidepanel() {
        
        // remove sidebar for user profile pages
        if ($this->template == 'user') {
            return;
        }
        
        $this->output('<div id="qam-sidepanel-toggle"><i class="icon-left-open-big"></i></div>');
        $this->output('<div class="qa-sidepanel" id="qam-sidepanel-mobile">');
        $this->qam_search();
        $this->widgets('side', 'top');
        
        /**
         * HERE WE WILL START TO CHECK THE PAGES
         * ACCORDING TO THE CURRENT PAGE WE WILL LOAD THE SIDEBAR METHOD
         *
         * YOU ALSO CAN WRITE CODE DIRECTLY WITHIN THE CONDITION INSTEAD OF METHODS
         */
        if ($this->template == 'qa') {
            $this->home_sidebar();
        } 
        elseif ($this->template == 'questions') {
            $this->q_list_sidebar();
        } 
        elseif ($this->template == 'question') {
            $this->q_view_sidebar();
        } 
        else {
            $this->sidebar();
        }

        // END OF THE SIDEBAR STUFFS
        
        $this->widgets('side', 'high');
        $this->nav('cat', 1);
        $this->widgets('side', 'low');
        if (isset($this->content['sidepanel'])) {
            $this->output_raw($this->content['sidepanel']);
        }
        $this->feed();
        $this->widgets('side', 'bottom');
        $this->output('</div>', '');
    }
    
    //...
    
}
...