Tutorial : Software : Cinema e Tv :
Briciole di pane
Pubblicato il Martedì, Novembre 18th, 2008 alle ore 12:48 / Scritto da Erfo / 0 Commenti

Ultimo post di una categoria

Categoria: Code Wordpress
banner

Il seguente codice ti da la possibilità di visualizzare l’ultimo o gli ultimi post di una determinata categoria del tuo Wordpress:

<?php $myposts = get_posts('numberposts=1&category=3');
foreach($myposts as $post) : ?>
<h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('j F Y') ?> <?php edit_post_link('Modifica','<strong>|</strong> ',''); ?>
<strong>|</strong>
<?php comments_popup_link('0 Commenti &#187;', '1 Commento &#187;', '% Commenti &#187;'); ?></small>
<?php setup_postdata($post); ?> <?php the_content(''); ?>
<?php endforeach; ?>

numberposts=1&category=3 significa che vedrai pubblicato un unico post (ovvero l’ultimo) della categoria con ID=3.
Se invece volessimo vedere gli ultimi 3 post della categoria 5 modificheremo i dati in questo modo:
numberposts=3&category=5

Non ci sono ancora commenti