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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * 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 ) );
}

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
[cc_actionscript][/cc_actionscript]          // Actionscript
[cc_actionscript3][/cc_actionscript3]        // Actionscript 3
[cc_css][/cc_css]                            // CSS Style Sheet
[cc_html][/cc_html]                          // HTML
[cc_js][/cc_js]                              // Javascript
[cc_objc][/cc_objc]                          // Objective-C
[cc_php][/cc_objc]                           // PHP
[cc_sql][/cc_sql]                            // SQL