Wordpress: add widget position


You can add just one widgetized area or you can segment it into different areas. Let’s add a top section and a bottom section within the content area of the page. Basically what we will need to do is register the areas that we want to be widgetized in our functions.php file. Then you can make a new page template that contains the new widgets that will be shown when added in the Appearance >> Widgets section of the dashboard.
Step 1: Register the widget areas in your functions.php file:

You should see this:

```if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '
<ul>
    <li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>
</ul>
',
'before_title' => '
<h2 class="widgettitle">',
'after_title' => '</h2>
',
));
```
Beneath it, register your two new widget areas by adding this:

```register_sidebars( 1,
array(
'name' => 'widgetized-page-top',
'before_widget' => '
<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>
',
'before_title' => '
<h2 class="widgettitle">',
'after_title' => '</h2>
'
)
);

register_sidebars( 1,
array(
'name' => 'widgetized-page-bottom',
'before_widget' => '
<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>
',
'before_title' => '
<h2 class="widgettitle">',
'after_title' => '</h2>
'
)
);
```
Step 2: Save a copy of your page.php (or other applicable page template) and optionally give it a different name. Then add this to the top so that WordPress recognizes it as a new page template:
   
```
<!--?php <br ?--> /*
Template Name: Widgetized Page
*/
?&gt;
```
Step 3: Add the widgets to your new page template inside the content div, just below (or above, if you’d rather) the php that calls the page content:
    
```
<!--?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("widgetized-page-top") ) : ?-->
<!--?php endif; ?-->

<!--?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("widgetized-page-bottom") ) : ?-->
<!--?php endif; ?-->

```
You can of course split those up and put static or dynamic content in between your multiple widgets. They just need to contain these basic elements.


Step 4:  Add widgets in the dashboard to your newly widgetized areas! If you created a new file then these will only show up on the custom template you’ve created. You can also use a conditional widget plugin to show the new widgets only on certain pages.

The same can be done for the header area, footers, posts, archives, 404 pages, index, alternate sidebar templates, multiple custom page templates, virtually anyplace within WordPress that you need to be widgetized.


Hebt u meer vragen? Een aanvraag indienen

Opmerkingen

Mogelijk gemaakt door Zendesk