Wordpress: functions.php, qualche funzione utile

venerdì 16 gennaio, 2009

Riprendendo l'ottimo post di Francesco Gavello WordPress Little Trick - functions.php e commenti nidificati sull'utilità del file functions.php presente nei temi Wordpress, ecco altre funzioni utili da utilizzare per tutti i vostri temi:

PHP:
  1. /**
  2.  * Recupera gli ultimi n post
  3.  *
  4.  * @param      $n     (number) Numero di post da estrarre
  5.  * @param      $c     (number) ID della categoria: lasciare vuoto per "tutte"
  6.  * @param      $b     (string) TAG (prima) usato per racchiudere i link (defautl <li>)
  7.  * @param      $a     (string) TAG (dopo) usato per racchiudere i link (defautl </li>)
  8.  *
  9.  * @result            (string) Elenco degli ultimi post
  10.  *
  11.  */
  12. function ul_get_recent_posts( $n = 5, $c = '', $b = "<li>", $a = "</li>" ) {
  13.     $o        = '';
  14.     $l        = new WP_Query( "showposts=" . $n.( ($c!='')?'&cat='.$c:'' ) );
  15.     while($l->have_posts()) {
  16.         $l->the_post();
  17.         $o .= $b.'<a rel="bookmark" title="Permanent Link: '.get_the_title().'" href="'.get_permalink().'">'.get_the_title().'</a>'.$a;
  18.     }
  19.     return $o;
  20. }  
  21.  
  22. /**
  23.  * Recupera il valore di custom field (campo personalizzato)
  24.  *
  25.  * @param    $k    (String) Chiave/ID del custom field
  26.  *
  27.  * @return                  Valore del Custom Field
  28.  */
  29. function ul_get_custom_field( $k ) {
  30.     global $post;
  31.     return( get_post_meta( $post->ID, $k, true ) );
  32. }

Post correlati

Questo articolo ti è stato utile?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

Non ci sono commenti per questo Post

Lascia un commento

TAG XHTML PERMESSI: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERIMENTO CODICE:
<pre></pre>         // blocco generico
[code][/code]       // blocco generico
[as][/as]           // Actionscript
[css][/css]         // CSS Style Sheet
[html][/html]       // HTML
[js][/js]           // Javascript
[objc][/objc]       // Objective-C
[php][/php]         // PHP
[sql][/sql]         // SQL