Zelig Planet

I briganti ti chiedono o la borsa o la vita, le donne tutte e due. (Samuel Butler)

Home Page - Blog - Informazioni

Archivio

cerca un articolo inserendo una o più parole qui sotto:

oppure seleziona un mese dall'elenco:

oppure scegli una categoria di articoli:

oppure visualizza la pagina dell'archivio

Misc

Feed RSS 0.92 Feed RSS 2.0 RSS 2.0 comm. Feed Atom 0.3 XHTML valido CSS valido Sottoscrivi con Bloglines

Powered by
WordPress 2.0.7

Archivio blog - giorno 23 Gennaio 2006

Wordpress plugin: Zelig Dropdown Cats

Lunedì 23 Gennaio 2006 by Zelig

english italian Articolo multilingue / Multilanguage post

This plugin displays the categories in the sidebar as a simple dropdown list (select box). Unlike the WP built-in dropdown_cats function, it gives the option to exclude some categories from the list.

I don’t know if there is already a similar plugin or if there is another way to do something like this, but it was funny to make and that’s enough for me!

INSTRUCTIONS:

  1. Download the zip file (current version is 1.4 of october 12, 2006).
  2. Extract the zelig-dropdown-cats.php file into the plugins directory in your WordPress installation (wp-content/plugins).
  3. Log in to WordPress administration. Go to the Plugins page and Activate this plugin.
  4. Put this code somewere in your template page, outside the loop (usually in sidebar):
<?php zelig_dropdown_cats(); ?>

IMPORTANT: if you are updating the plugin from version 1.0 or 1.1, please remove all the code formerly required at this point and leave only the function call, as indicated above.

The zelig_dropdown_cats() function has some parameters you can pass:

Parameter Values Description Default
sort_column name
id
sort list by name or id number id
sort_order asc
desc
sorting direction of the list (ascending or descending) asc
file string name of the php file used to display selected categories (NOT WORKING!) index.php
hide_empty 0
1
1 means hide empty categories, 0 shows them too 1
exclude number or comma separated list of numbers these are the categories (ID numbers) to exclude from the list  
post_count 0
1
if set to 1, display the count of posts in each category 0
title string text appearing in the list box when it’s closed. If you don’t want the first row as a title, use this parameter without any value (’title=’) “Categories” (or corresponding localized text)
boxwidth number width size (in pixel) of the list box. If you don’t use this parameter or if you set it to 0, the list box will assume the width of the longest category name it contains. If you set a width value, longer names may be truncated at that point, depending on browser (IE6…) 0
child_of number If not set or if set to -1, shows all categories and subcategories. If set to 0, shows only main categories excluding all subcategories. If set with a category ID number, shows only its subcategories. -1

EXAMPLES:

<?php zelig_dropdown_cats('sort_column=name'); ?>

displays list sorted by name.

<?php zelig_dropdown_cats('sort_column=name&exclude=1,3,5,6'); ?>

displays list sorted by name, excluding categories id 1, 3, 5 and 6.

<?php zelig_dropdown_cats('sort_order=desc&hide_empty=0'); ?>

displays list in descending ID order, showing also empty categories.

<?php zelig_dropdown_cats('title=Select category&boxwidth=120'); ?>

shows “Select category” as a title in the list box and set the width to 120 pixels.

<?php zelig_dropdown_cats('title=&post_count=1&child_of=0'); ?>

don’t shows the first row with the title, adds the post count for every category and lists only main categories excluding subcategories.

NOTES:

The output code is valid XHTML Strict.
Tested with WordPress 1.5.2 and 2.0.x.

CHANGE LOG:

  • Version 1.4 (october 12, 2006): added “child_of” option to exclude the visualization of all subcategories or to show only subcategories of a given category. Another little upgrade lets you use more than one istance of the function in the same page.
  • Version 1.3 (august 26, 2006): now you can exclude the first row of the list with the title. Added localization support (translation of “Categories”, if available) as a default title.
  • Version 1.2 (august 14, 2006): semplified the code to put in the sidebar and added two new options “title” and “boxwidth”.
  • Version 1.1 (june 7, 2006): added “post_count” option to display a count of posts in each category after the name.

Look here for all the Wordpress plugins from Zelig!


Copyright © 1997-2009 Corrado "Zelig". Tutti i diritti riservati (vedi note legali)

NB: state visualizzando questo sito nella versione ottimizzata per dispositivi portatili (cellulari, palmari, ecc.) oppure con un browser "datato" che non consente di visualizzare correttamente i fogli di stile (CSS). I contenuti del sito sono comunque gli stessi e le differenze riguardano solamente l'aspetto estetico, che sarebbe molto più "piacevole" se visualizzato con un browser più recente!