How to build widgets?

I'm looking for educational resources on how to build widgets. My hope is that I can find a theme that works with Buddypress and Multisite and the homepage is fully widgetized so I can constantly customize what content is on the homepage.

My thought is that if I have a theme that is fully widgetized I can figure out how to layout the homepage the way I want with custom widgets and various plugins without getting too deep in the code.

Thoughts/resource suggestions on building widgets? Am I headed in the right direction?

Thanks!
Jeff

  • Arun Basil Lal
    • New Recruit

    Hello kauffey19,

    Those tutorials should help you. Let me summarize the idea for you. This is how most themes do it.

    - The Widget is registered in functions.php using the register_widget function: http://codex.wordpress.org/Function_Reference/register_widget
    - Usually the sidebar is widget-ized and sidebar.php will have the code snippet on how to use it in the theme.

    So basically you have to do these:
    - Duplicate the register_widget code and change the name of the sidebar to something new. Looks something like (from Twenty Ten Theme):

    register_sidebar( array(
    		'name' => __( 'Primary Widget Area', 'twentyten' ),
    		'id' => 'primary-widget-area',
    		'description' => __( 'The primary widget area', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    "Primary Widget Area" is what is shown to the user on the Widgets page in the admin and "primary-widget-area" is the id. Change both.

    Now in your theme file, wherever you want to use it, use this snippet:

    if ( is_active_sidebar( 'primary-widget-area' ) ) : ?>
    
    		<div id="primary" class="widget-area" role="complementary">
    			<ul class="xoxo">
    				<?php dynamic_sidebar( 'primary-widget-area' ); ?>
    			</ul>
    		</div><!-- #primary-widget-area -->

    That should work :slight_smile:

    Good luck!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.