Wordpress: functions.php, qualche funzione utile
venerdì 16 gennaio, 2009Riprendendo 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:
-
/**
-
* Recupera gli ultimi n post
-
*
-
* @param $n (number) Numero di post da estrarre
-
* @param $c (number) ID della categoria: lasciare vuoto per "tutte"
-
* @param $b (string) TAG (prima) usato per racchiudere i link (defautl <li>)
-
* @param $a (string) TAG (dopo) usato per racchiudere i link (defautl </li>)
-
*
-
* @result (string) Elenco degli ultimi post
-
*
-
*/
-
function ul_get_recent_posts( $n = 5, $c = '', $b = "<li>", $a = "</li>" ) {
-
$o = '';
-
$l = new WP_Query( "showposts=" . $n.( ($c!='')?'&cat='.$c:'' ) );
-
while($l->have_posts()) {
-
$l->the_post();
-
$o .= $b.'<a rel="bookmark" title="Permanent Link: '.get_the_title().'" href="'.get_permalink().'">'.get_the_title().'</a>'.$a;
-
}
-
return $o;
-
}
-
-
/**
-
* Recupera il valore di custom field (campo personalizzato)
-
*
-
* @param $k (String) Chiave/ID del custom field
-
*
-
* @return Valore del Custom Field
-
*/
-
function ul_get_custom_field( $k ) {
-
global $post;
-
return( get_post_meta( $post->ID, $k, true ) );
-
}










19

Non ci sono commenti per questo Post
Lascia un commento