Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

How to create widget area in word press ?

Here in word press development , how can we add widget area ??

is this one ?? <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" /> !!!

ya ! its such a nice question, but he is asking about register_sidebar(), but i want to create a widget area under neath of the slider part for marquee purpose . how can i write code for that ??

2 Answers

Hi Mohan,

Please take a look over this question it should hold everything you need :)

Craig

Sorry Mohan,

If you refer to the below this will set you up the correct code in your functions.php and then let you call that widgetized area in your theme templates.

So.....

Functions.php file:

<?php 

//Add theme support for widgetized areas / create widget
function create_widget($name, $id, $description) {

    register_sidebar(array(
        'name' => __( $name ),   
        'id' => $id, 
        'description' => __( $description ),
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="widget-header">',
        'after_title' => '</h3>'
    ));

}

// Create widgets 
create_widget("Front Page", "front-page", "Displays on the home page");

?>

Adding the above creates a function called "create_widget" which accepts 3 params. Name, ID, Description. To actually create a widget you then call that function and pass your chosen params.

Next you need to call for that widget in your template file where you wish is to be displayed like the below:

<div class="font-page-widget">

    <?php if( !dynamic_sidebar( 'front-page' ) ): ?>

        <p>Please Add Widget Front Page</p>

    <?php endif; ?>

</div>

Thats the code from the question you need to get going :)

To create more widgetized areas simply call the function again passing new params and then drop the "if dynamic sidebar" code snippet into your desired template file.

Craig

wow ! thank you so much bro. Thank you. will you plz tell me how to add jQuery ? using php for wp theme development !!!