Skip to content

Instantly share code, notes, and snippets.

@diije
Created May 18, 2017 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diije/eaa75cce2fc17b14113288314892ebb4 to your computer and use it in GitHub Desktop.
Save diije/eaa75cce2fc17b14113288314892ebb4 to your computer and use it in GitHub Desktop.
WordPress : Afficher le widget des articles récents sur toutes les pages sauf la page d'accueil.
<?php
if ( ! function_exists('dfr_recent_articles') ) {
function dfr_recent_articles() {
if(!(is_home() || is_front_page())) {
echo '<section id="dfr_widget" class="widget widget_recent_entries">';
echo '<h2 class="widget-title">Articles R&eacute;cents</h2>';
echo '<ul>';
$lastposts = get_posts();
foreach ( $lastposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li>
<?php endforeach;
echo '</ul>';
echo '</section>';
}
}
wp_register_sidebar_widget(
'dfr_widget',
'Mes Articles R&eacute;cents',
'dfr_recent_articles',
array( 'description' => 'Affiche les articles r&eacute;cents seulement sur les pages internes.' )
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment