WordPress.org

Forums

How to widgetize two sidebars? (6 posts)

  1. Machi
    Member
    Posted 7 years ago #

    Hi, I'm widget newbie and I have a very strange problem. I have to widgetize two sidebars. In functions.php I have:

    <?php
    if ( function_exists('register_sidebar') )
        register_sidebars(2);
    ?>

    and in sidebar.php:

    <div id="side">
    	<div id="sideleft">
    	<ul>
    		<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>
                	...
            	<?php endif; ?>
        	</ul>
    	</div>
        <div id="sideright">
        	<ul>
        		<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2)) : else : ?>
    
            	<?php endif; ?>
            </ul>
    	</div>
    </div>

    Please, where can be problem? In other theme which I downloaded from internet is this code working :(

    Thanks a lot...

  2. Machi
    Member
    Posted 7 years ago #

    nobody knows? :( please help me

  3. Alex Cragg
    Member
    Posted 7 years ago #

    try this code in the functions.php file

    <?php
    if ( function_exists('register_sidebar') )
    {
    register_sidebar(array('name'=>'Left Sidebar'));
    register_sidebar(array('name'=>'Right Sidebar'));
    }
    ?>

    and this in the sidebar - make sure to change it to 'Right Sidebar' in your second div

    <?php if ( !function_exists('dynamic_sidebar')
            || !dynamic_sidebar('Left Sidebar') ) : ?>
    <?php endif; ?>

    the beauty of this is that you can name your sidebars - makes for easier editing

  4. Machi
    Member
    Posted 7 years ago #

    epicalex: Works great! Thanks, thanks, thanks, ... :)

  5. eches
    Member
    Posted 7 years ago #

    I had the same problem as machi had previously. I later found the error is originated from space between closed bracket (i.e ')') at the first line of the code.

    <?php if ( function_exists('register_sidebar') )
     register_sidebars(2); ?>

    Remove the space between both closed brackets and it should fix the problem.

  6. zaussome
    Member
    Posted 7 years ago #

    Remove the space between both closed brackets and it should fix the problem.

    PHP ignores whitespace, how can that make a difference? If I understood you correctly.

Topic Closed

This topic has been closed to new replies.

About this Topic