• Hi.
    My websites has several pages, and I would like to have diffrent sidebars for those pages.

    As I have understood I can add the code below to my function.php
    But my question is, what do I then do? How Do I register new sidebars codes and where? And how do I call them to appear on a spesific page?

    : <?php
    /**
     * Functions - Framework gatekeeper
     *
     * This file defines a few constants variables, loads up the core framework file,
     * and finally initialises the main WP Framework Class.
     *
     * @package WPFramework
     * @subpackage Functions
     */
    
    define( 'WP_FRAMEWORK', '0.2.4' ); // Defines current version for WP Framework
    
    	/* Blast you red baron! Initialise WP Framework */
    	require_once( TEMPLATEPATH . '/library/framework.php' );
    	WPFramework::init();
    
    // Register sidebars
    if ( function_exists('register_sidebar') )
            {
            register_sidebar(array(
            'name' => 'Left Side',
            'before_widget' => '<div id="%1$s" class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h4>',
            'after_title' => '</h4>',
            ));
    
            register_sidebar(array(
            'name' => 'Right Side',
            'before_widget' => '<div id="%1$s" class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h4>',
            'after_title' => '</h4>',
            ));
    
    }
    ?>
Viewing 14 replies - 1 through 14 (of 14 total)
  • Hi sunsi55.

    Maybe it’s much easier to install a plugin like Custom Sidebars and create the bars using the admin area.

    It’s easy to use following its instructions.

    If you can code WP themes you could try creating a Page Template that uses a Custom Field as a Paramater.
    Depending on that Custom Field you can select a different sidebar with a PHP function.
    Or you could try the plugin mentioned by marquex.

    you probably already have a bit of code that looks like this:

    if ( function_exists('register_sidebar') ) {
    	register_sidebar(array(
    		'name'=>'Sidebar',
    		'before_widget' => '<li class="widget" id="%1$s"><div class="widgetBG">',
    		'after_widget' => '</div><div class="widgetBottom"></div></li>',
    		'before_title' => '<div class="widgetTitle">',
    		'after_title' => '</div>'
    	));

    that registers your main/first sidebar. which is the file called sidebar.php. You can add sidebars to that code, registering as many as you like. So for instance:

    if ( function_exists('register_sidebar') ) {
    	register_sidebar(array(
    		'name'=>'Sidebar',
    		'before_widget' => '<li class="widget" id="%1$s"><div class="widgetBG">',
    		'after_widget' => '</div><div class="widgetBottom"></div></li>',
    		'before_title' => '<div class="widgetTitle">',
    		'after_title' => '</div>'
    	));
    	register_sidebar(array(
    		'name'=>'TopWidget',
    		'before_widget' => '<li class="topWidget" id="%1$s"><div class="topWidgetBG">',
    		'after_widget' => '</div><div class="topWidgetBottom"></div></li>',
    		'before_title' => '<div class="topWidgetTitle"><span class="topText">',
    		'after_title' => '</span></div>'
    	));

    includes the original sidebar as I’ve shown above. Then it goes on to add another sidebar, this one named TopWidget. I use it in my theme to add a widget area just under the header. Just as the first sidebar was named ‘Sidebar’ and referenced sidebar.php, the new one I added is named ‘TopWidget’, so I’m able to make a new file in my theme and name it sidebar-TopWidget.php. I used the code form my sidebar.php to guide me in codeing my new sidebar file. So now the sidebar is registered in functions.php, and I’ve made the actual sidebar file.

    The final bit is to call in the sidebar which is done by:
    <?php get_sidebar('topWidget'); ?>

    which calls in my new sidebar. Now, sidebar is just what these are called. They don’t have to be fiull sidebars. They are just widget ready areas. You can put ‘sidebars’ anywhere you want a widget.

    And finally, the harder part. It is easy to drop different sidebars on different templates. But if you want to have different sidebar on your front page, vs another specific page, that can be done using conditionals.

    https://codex.www.ads-software.com/Conditional_Tags

    But that all depends exactly how you want to do things

    Thread Starter sunsi55

    (@sunsi55)

    Thanks for all great answers!
    In general my sidebars contains pictures, lets say picture A, and Picture B.
    At the moment, the code is farily simple:

    <a href="https://x.com/home"><img class="alignnone size-full wp-image-16" title="Pictitle" src="https://x.com/x/wp-content/uploads/2010/09/PicA.jpg" alt="" width="180" height="150" " Heihei" /></a>
    <a href="https://x.com/Home"><img class="alignnone size-full wp-image-16" title="Pictitle"src="https://x.com/x/x/uploads/2010/09/PicB.jpg" alt="" width="780" height="80" " Heihei" /></a>

    That is for my frontpage, but for my About page I would like Pic C, and Pic D to appear.

    Which of the solutions mentioned over is the easiest and best for me?
    I Would love if anyone could explain exactley what to then write in my new code, and where to write it?
    Once again, thanks alot for helping! ??

    Thread Starter sunsi55

    (@sunsi55)

    Rev.VooDoo Where have you writen the coding for your topwidget? How do you make a new php.file?
    Thanks for helping! ??

    Nice solutions.
    Thanks for helping

    Mauricio
    4 Cores Comunica??o

    you can’t make a new php file from within WordPress.

    You have to do it with ftp, or in a file manager if your host offers one.

    I simply copied my sidebar.php, and renamed it to sidebar-TopWidget.php

    Once the file is made, it will be available to be edited within WPs theme editor.

    However, if you are just swapping out pictueres, that may be simpler done using conditionals with that link I provided earlier.

    Thread Starter sunsi55

    (@sunsi55)

    Okey. Thanks for helping! I am going to work on it for the rest on the evenig, And I will give you an update in this treath on how I am doing later on!
    Thanks for the great help! ??

    Only thing I need to do is to get a new simple code for my sidebars.
    And know how to call them to a spesific page!

    I don`t know anything about FTP, but I guess I can try to learn it!
    So I can`t code a new sidebar without FTP? ??

    Thread Starter sunsi55

    (@sunsi55)

    My Host offer a filemanger.
    How do I proceed?
    I have the code for my new sidebar. Then what to do?
    How do i Get that sidebar2.php file availeble for my wordpress site?

    just make a new file within your theme. Like on my host (godaddy) I can go into my theme’s folder and click new. It will open up a window, I paste my code into the window and click save, it will ask for the title, and done. Just make sure the new sidebar2.php file is in the same folder as the original sidebar.php, they should be in the same place

    Thread Starter sunsi55

    (@sunsi55)

    Okey.
    And when I have done this it will appear with my other .php files when I log into the wp – admin dashdboard? ??

    yes that is correct!

    Thread Starter sunsi55

    (@sunsi55)

    Okey. Great Ill try to get it to work tonight, and I give you a post here after to tell you how things have gone ??
    Thanks for all help! ??

    Thread Starter sunsi55

    (@sunsi55)

    Hi Again! ??
    I have now fixed so I have a sidebar2.php file also.
    My org sidebar, is named: sidebar.php

    But I don`t understand what to write in my functions.php. I have tried using the code you posted, just replacing topwidget.php with sidebar2.php, but I get some errors.

    What should I do now? If you need to know my sidebar.php codes it is written in a post a little higher in this post!
    Thanks again for helping! ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Custom Sidebars to each page on my website’ is closed to new replies.