Question

I'm a Java programmer, but knows PHP as well. Now I'm trying to enhance my skills in PHP and Wordpress. I had created a wordpress theme recently and now I'm trying to register my sidebar to make it widget ready. I'm following some tutorials(registering sidebar), but it seems that it is not clear to me how will I do it in my case. I just don't know what will I put on the following stuff.

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
?>

and here is my current sidebar

<div id="primary-sidebar">      
        <a href="?"><img src="<?php bloginfo('template_directory'); ?>/images/logo.jpg" alt="Company Logo" class="logo" /></a>
            <ul class="menu">       
                <li><a href="?" <?php echo ($page == NULL) ? 'class="active"': '';?>>Home</a></li>
                <li><a href="?page=philosophy" <?php echo ($page == 'philosophy') ? 'class="active"': '';?>>Philosophy</a></li>
                <li><a href="?page=investments" <?php echo ($page == 'investments') ? 'class="active"': '';?>>Investments</a></li>
                <li>
                    <a href="?page=about" <?php echo ($page == 'about') ? '': '';?>>About Us</a>
                    <ul>
                        <li><a href="?page=team" <?php echo ($page == 'team') ? 'class="active"': '';?>>Our Team</a></li>
                        <li><a href="?page=company" <?php echo ($page == 'company') ? '': '';?>>Company Profile</a></li>
                    </ul>
                </li>           
            <li><a href="?page=contact" <?php echo ($page == 'contact') ? 'class="active"': '';?>>Contact Us</a></li>
            </ul> <!-- END OF MENU -->
    </div> <!-- END OF PRIMARY SIDEBAR -->

Can you help me with this, mates? Any help and comments/suggestions will be greatly appreciated. Thank you so much.

Was it helpful?

Solution

Create a functions.php file (if you haven't done so already) and add this code:

<?php

function register_sidebar() {
  register_sidebar(array(
    'name' => '',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '',
    'after_title' => '',
  ));
}

add_action('init', 'register_sidebar');

?>

OTHER TIPS

function register_sidebar() {
  register_sidebar(array(
    'name' => '',      //this is the widgets name , it shows up in admin
     'id' => '',      // this is widget ID, must have to actually call it
     'description'   => '', // under name in admin, not needed
    'before_widget' => '', // HTML placed before ( usually a div)
    'after_widget' => '', // HTML placed after ( usually a div)
    'before_title' => '', // HTML placed before title( usually a div)
    'after_title' => '',  // HTML placed before after ( usually a div)
  ));
}

add_action('init', 'register_sidebar');

To call the sidebar you write, <?php dynamic_sidebar( 'id' ); ?>

I think the only needed parameter is the ID and the name when you register it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top