18 juin
Astuces et articles / Astuces html css
Comment afficher les articles mis en avant sur wordpress ?
- Cédric Verlucco
- code, developpement, wordpress
- 0 Commentaires
Sur la partie administration de wordpress
Pour rappel, pour mettre un article en avant dans l’administration, rien de plus simple :Lors de l’édition d’un article wordpress, dans la colonne de droite et le cadre publier, vous trouverez le texte “Visibilité : Public Modifier”. Cliquez sur “Modifier” et cochez la case “Mettre cet article en avant sur la page d’accueil”
Maintenant la partie développeur wordpress
Vous allez insérer ce code là où vous voulez afficher votre article mis en avant :<?php $recentPosts = new WP_Query(); $sticky = get_option(‘sticky_posts’); $args = array( ‘showposts’ => 3, ‘post__in’ => $sticky, ‘caller_get_posts’ => 1, ‘orderby’ => ‘date’, ); $recentPosts->query($args); while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <div> <?php if ( has_post_thumbnail()) : ?> <h3><a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></h3> <a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>” ><?php the_post_thumbnail(‘large’); ?></a> <?php the_excerpt(25); ?><a class=”lire-la-suite” href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”>Lire</a> <?php endif; ?> </div> <?php endwhile; ?> </div>
