A partire dalla versione 2.2, i Widget di WordPress permettono di gestire la visibilità e l’ordinamento di vari elementi all’interno della barra laterale del blog. Ad esempio la lista delle Categorie, dell’Archivio mensile, i Post più letti etc…
Per poter utilizzare questa funzionalità bisogna installare anche un tema che supporti i Widget. La maggior parte dei temi lo è, ma nel caso in cui il tema scelto non fosse compatibile o che l’utente voglia crearsene uno da zero, bisogna effettuare delle modifiche. Ecco quali:
Passo 1: Creare (o modificare) il file functions.php
Se nella cartella del proprio tema il file functions.php
non esiste, va creato e al suo interno va inserito questo codice:
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '
',
'after_widget' => '',
'before_title' => '
',
));
}
Passo 2: Aggiungere una Sidebar dinamica al Tema
Per mostrare i Widget, è necessario modificare il file sidebar.php
inserendo questa riga:
if ( !function_exists('dynamic_sidebar') || ! dynamic_sidebar() ) :
// codice html da mostrare se i Widget non sono supportati
endif;
Passo 3: modificare il file functions.php
per aggiungere Sidebar multiple
Per aggiungere altre sidebar, modifichiamo il file functions.php
in questo modo:
// sidebar 1
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name'=>'sidebar1',
'before_widget' => '
',
'after_widget' => '',
'before_title' => '
',
));
}
// sidebar 2
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name'=>'sidebar2',
'before_widget' => '
',
'after_widget' => '',
'before_title' => '
',
));
}
Passo 4: Aggiungere le Sidebar multiple al Tema
Per aggiungere le due nuove Sidebar dinamiche appena create, al nostro tema, è sufficiente modificare il file sidebar.php
in questo modo
// sidebar 1
if ( !function_exists('dynamic_sidebar') || ! dynamic_sidebar('sidebar1') ) :
// codice html da mostrare se i Widget non sono supportati
endif;
// sidebar 2
if ( !function_exists('dynamic_sidebar') || ! dynamic_sidebar('sidebar2') ) :
// codice html da mostrare se i Widget non sono supportati
endif;
Passo 5: Aggiungere una descrizione alle Sidebar (solo per WP .2.9)
A partire dalla versione 2.9, WordPress supporta anche le descrizioni delle varie Sidebar: basta aggiungere all’array passato alla funzione register_sidebar
l’elemento description
:
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name'=>'sidebar1',
'description' => 'Sidebar Numero 1',
'before_widget' => '
',
'after_widget' => '',
'before_title' => '
',
));
}
Link correlati
Le 10 migliori librerie PHP per la creazione di documenti PDF.
PHP
Here are 10 essential HTML5 frameworks you should have in your designer arsenal right now if you are serious about adopting HTML5 development into your daily workflow.
HTML5
Ten fresh responsive wordpress themes which are all free.
Temi WordPress
In this article, I’m going to show you 10+ SQL queries to clean up your WordPress database.
Database, WordPress
Today in this article, I have put together these excellent, high-quality, fresh, Free WordPress 3.0 Themes to enhance your blogging experience.
Temi WordPress
Whether you are an artist, graphic designer, photographer or a magazine or newspaper owner, you would require some real catchy and awesome creative WordPress themes to display your work.
Temi WordPress
It has been awhile since I’ve created one of our popular WordPress theme galleries, so I decided it was time to build a new one.
Temi WordPress, Tools e Risorse
“Add From Server” is a quick plugin which allows you to import media & files into the WordPress uploads manager from the Webservers file
Plugin WordPress
In this post we’ll look at the different aspects of WordPress theme development, starting with the fundamentals and then moving swiftly onto the basics, template tags and the more advanced files.
Temi WordPress, Tutorial WordPress
Recently I needed to create a page in WordPress that didn’t have the sidebar on it. Took me a while to find the solution, but the one I found works like a charm. Takes a bit of programming knowledge, but not too bad.
Temi WordPress, Tutorial WordPress
In this article we are going to look at media queries, have a code snippet you can use to start your media queries and show how you can combine CSS transition with the media queries to show an animated change to your elements.
CSS
Display your latest tweets on your website or blog with a jQuery plugin and a PHP class.
jQuery, PHP
Featplug is a standalone script / wordpress plugin that can mine your WordPress posts or any other data and look for images suiting a given dimension and generates ‘featured’ section for your site using the found items.
Plugin WordPress
I have put together this post that examines the WordPress template hierarchy and the use of conditional statements. Technically you only need two files for a WordPress theme to work, index.php and style.css.
Temi WordPress
How you can easily display your latest Google+ update on your WordPress blog.
Hack WordPress
WordPress default behavior is to load JavaScript in the <head> page.
This plugin will move all javascript code to the footer if the plugins have declared JavaScript properly.
Plugin WordPress
MTR Podcast Recorder offers real-time recording (via a Java applet) that is saved into MP3 format on the same server where WordPress is installed.
Plugin WordPress
This plugin allows you to make a WordPress page or post link to a URL of your choosing, instead of its WordPress page or post URL. It also will redirect people who go to the old (or “normal”) URL to the new one you’ve chosen.
Plugin WordPress
Plugin che permette di estendere la ricerca di default di WordPress anche alle Pagine, alle Categorie e ai Tag, ai Commenti (con possibilità di escludere o includere quelli approvati), alle Bozze, gli estratti e gli allegati e ai Campi personalizzati. E’ possibile inoltre, escludere dalla ricerca gli Articoli e le Categorie, a scelta.
Plugin WordPress
When searching the Web for free themes outside the WordPress directory, be aware that the popularity, open code, and ease of use in making WordPress themes are attractive to others who can make your web server could become part of a zombie army of machines participating in a DDoS attack on some other website, but some may contain malicious code in there.
Temi WordPress
An useful snippet to cache custom queries in WordPress. Don’t forget to update the query on line 5!
Database, Hack WordPress
As WordPress is the most popular and secure platform today, it is obvious that there is plethora of great responsive WordPress themes out there. Here are some of the best available.
Temi WordPress
Here is a WordPress snippet to create your own WordPress Widgets.
Plugin WordPress
Plugin per WordPress che rende uguale l’altezza delle colonne del tema usato, ad esempio la barra laterale e la colonna principale.
Plugin WordPress
A simple way to add the FancyZoom image overlay script to your blog. In short, FancyZoom is a nice, modern way of making popup images.
Ajax, Javascript, Plugin WordPress