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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?php
function lastPosts($nombre = 1, $typeCont = 'cont') {
if($nombre == '') $nombre = 1;
if($typeCont == '') $typeCont = 'cont';
echo fb_lastposts('', $nombre, $typeCont);
}
function fb_the_content($more_link_text = null, $stripteaser = 0) {
$content = get_the_content($more_link_text, $stripteaser);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
function fb_lastposts($atts, $nombre, $typeCont) {
// si la fonction est appelee par le shortcode
extract(shortcode_atts(array(
"nb" => '1',
"cont" => 'cont',
"cat" => '', /* sert (servait) a faire un tri selon la categorie - methode obsolete apparement */
), $atts));
// si la fonction est apelee par lastPosts() (code php dans template du theme)
if($nombre > 1) $nb = $nombre;
if($typeCont != 'last-posts') $cont = $typeCont;
$category = ($cat != '' ? '&category='.$cat : '');
global $post;
$myposts = get_posts('numberposts='.$nb.'&order=DESC&orderby=post_date'.$category);
$retour= PHP_EOL.'<div class="display-last-posts">'.PHP_EOL;
foreach($myposts as $post) :
$cn = get_comments_number();
if($cn < 1) { $isAre = 'are'; $commentsText = 'no comments'; }
elseif($cn == 1) { $isAre = 'is'; $commentsText = '1 comment'; }
else { $isAre = 'are'; $commentsText = $cn.' comments'; }
setup_postdata($post);
$retour.='<h3><a href="'.get_permalink().'">'.the_title("","",false).'</a></h3>'.PHP_EOL;
if ($cont != 'cont') { $retour.= get_the_excerpt().PHP_EOL; } else $retour.= fb_the_content().PHP_EOL;
endforeach;
$retour.='</div> ';
return $retour;
}
add_shortcode("last-posts", "fb_lastposts");
?> |
Partager