Come rendere il tuo tema WordPress compatibile coi widget
giovedì 2 settembre 2010
Lo so, ormai è un argomento vecchiotto, ma metti caso che ci sia chi – come me – non aveva ancora reso il suo tema del proprio WordPress compatibile con i nuovi widget!
Ormai tutti i temi sono widget-ready, cioè pronti per permetterci di usare i widget, ma se qualcuno avesse tra le mani un tema vecchio, e volesse poter usare i widget ecco come fare in DUE PASSI!
La prima cosa da fare è aprire il file del nostro tema che si chiama ‘functions.php‘ ed aggiungere le seguenti righe di codice:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Widgetized Area',
'id' => 'widgetized-area',
'description' => 'This is a widgetized area.',
'before_widget' => '<div id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
Dopodiché si apre il file ‘sidebar.php‘ per inserire il codice che servirà a far apparire i widget:
<div id="widgetized-area">
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('widgetized-area')) : else : ?>
<div>
<p><strong>Widgetized Area</strong></p>
</div>
<?php endif; ?>
</div>
Chiaramente questo codice possiamo metterlo dove vogliamo metterlo in altri posti nel nostro tema, si può fare!






