Sid Gifari From Gifari Industries - BD Cyber Security Team
Home
/
home
/
airmobeuag
/
2020
/
wp-content
/
plugins
/
afficher-blog
/
✏️
Editing: index.php
<?php /** * @package Afficher articles * @version 1.0 */ /* Plugin Name: Afficher article de blog Description: juste une boucle pour afficher les articles du blog sur WordPRess Author: Kevin Chauvet Version: 1.0 Author URI: https://astianax.fr */ function shortcode_articles() { global $post; global $output; $args = array( 'order'=> 'DESC', 'orderby' => 'publish_date', 'posts_per_page' => 3 ); $the_query = new WP_Query( $args ); // the loop if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $title = get_the_title(); $short_title = wp_trim_words( $title, 5, '...' ); $authorLink = get_the_author_meta('nickname'); $date = get_the_date(); $imgUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); $output .= '<div class="article"><img src="' . $imgUrl . '"><h4><a href="' . get_post_permalink() . '\">' . $short_title . '</a></h4><p>Par ' . $authorLink . ', le ' . $date . '</p></div>'; endwhile; endif; wp_reset_query(); return '<div class="articles">' . $output . '</div>'; } add_shortcode('articles', 'shortcode_articles');
💾 Save
❌ Cancel