- Statut : non résolu
- Ce sujet contient 7 réponses, 3 participants et a été mis à jour pour la dernière fois par
Tche, le il y a 9 années et 10 mois.
-
AuteurMessages
-
20 février 2015 à 11 h 23 min #547499
Bonjour,
Ma configuration WP actuelle
– Version de WordPress : 4.1.1.
– Version de PHP/MySQL :
– Thème utilisé : Twentyfourteen-child
– Extensions en place : Akismet, comment popularity, post-viewed recently, netscript, supersocializer, user-submitted post, theme my login…
– Nom de l’hebergeur : OVH
– Adresse du site : allwewish.orgProblème(s) rencontré(s) :
J’aimerais ajouter la date au widget « derniers commentaires » natif de wordpress. J’ai cherché un plugin qui pouvait le faire sans succès. J’ai donc cherché de la doc pour le faire moi-même et je suis tombé sur deux tutos intéressants:
1. Pour ajouter un widget (http://wpchannel.com/ajouter-widget-personnalise-tableau-bord-wordpress/):
// Ajouter un widget dans le tableau de bord de WordPress
function wpc_dashboard_widget_function() {
// Saisie du texte entre les guillemets
echo »
<ul>
<li>Date de réalisation : mai 2011</li>
<li>Auteurs : Aurélien Denis.</li>
<li>Hébergement : Mavenhosting</li>
</ul>
« ;
}
function wpc_add_dashboard_widgets() {
wp_add_dashboard_widget(‘wp_dashboard_widget’, ‘Informations techniques’, ‘wpc_dashboard_widget_function’);
}
add_action(‘wp_dashboard_setup’, ‘wpc_add_dashboard_widgets’ );2. Pour créer son propre plugin ‘commentaires récents’ personnalisé (http://wplancer.com/how-to-display-recent-comments-without-using-a-plugin-or-widget/):
<?php
/**
* Show Recent Comments
*
* @author Baki Goxhaj
* @link http://wplancer.com/how-to-display-recent-comments-without-using-a-plugin-or-widget/
*
* @param string/integer $no_comments
* @param string/integer $comment_len
* @param string/integer $avatar_size
*
* @echo string $comm
*/
function bg_recent_comments($no_comments = 5, $comment_len = 80, $avatar_size = 48) {
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query( array( ‘number’ => $no_comments ) );
$comm = »;
if ( $comments ) : foreach ( $comments as $comment ) :
$comm .= ‘<li><a class="author" href="' . get_permalink( $comment->comment_post_ID ) . ‘#comment-‘ . $comment->comment_ID . ‘ »>’;
$comm .= get_avatar( $comment->comment_author_email, $avatar_size );
$comm .= get_comment_author( $comment->comment_ID ) . ‘:</a> ‘;
$comm .= ‘<p>‘ . strip_tags( substr( apply_filters( ‘get_comment_text’, $comment->comment_content ), 0, $comment_len ) ) . ‘…</p></li>‘;
endforeach; else :
$comm .= ‘No comments.’;
endif;
echo $comm;
}Seulement voilà quand j’essaie d’intégrer les deux dans mon functions.php rien ne se passe ni dans mon admin (pas de nv widget), ni sur le site (même pas d’erreur)
///Ajouter un commentaires récents perso
function aww_recent_comments($no_comments = 5, $comment_len = 80, $avatar_size = 48) {
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query( array( ‘number’ => $no_comments ) );
$comm = »;
if ( $comments ) : foreach ( $comments as $comment ) :
$comm .= ‘<li><a class="author" href="' . get_permalink( $comment->comment_post_ID ) . ‘#comment-‘ . $comment->comment_ID . ‘ »>’;
$comm .= get_avatar( $comment->comment_author_email, $avatar_size );
$comm .= get_comment_author( $comment->comment_ID ) . ‘:</a> ‘;
$comm .= ‘<p>‘ . strip_tags( substr( apply_filters( ‘get_comment_text’, $comment->comment_content ), 0, $comment_len ) ) . ‘…</p></li>‘;
endforeach; else :
$comm .= ‘No comments.’;
endif;
echo $comm;
}
function wpc_add_dashboard_widgets() {
wp_add_dashboard_widget(‘wp_dashboard_widget’, ‘Informations techniques’, ‘wpc_dashboard_widget_function’);
}
// Register the new dashboard widget with the ‘wp_dashboard_setup’ action
add_action(‘wp_dashboard_setup’, ‘wpc_add_dashboard_widgets’ );Est-ce-que quelqu’un pourrait m’éclairer?
Un énorme merci d’avance pour votre aide!
Tche21 février 2015 à 9 h 59 min #996022un petit up
21 février 2015 à 12 h 07 min #996023Bon, j’ai refait un tour des plugins et après tests WP Better recent comments permet bien d’afficher la date et est en fait hyper personnalisable. Cela dit si qqn a le solution pour se passer d’un plugin qui n’a plus été mis à jour depuis un an et qui n’a pas été testé avec wp 4.1.1. (chez moi ça marche) Elle est la bienvenue. 🙂
17 août 2015 à 9 h 43 min #996024En essayant d’accélérer le site et de diminuer le nombre d’extensions… j’approche enfin du but:
///Personnaliser les commentaires récents
function aww_recent_comments($no_comments = 10, $comment_len = 80, $avatar_size = 16) {
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query( array( ‘number’ => $no_comments ) );
$comm = »;
if ( $comments ) : foreach ( $comments as $comment ) :
$comm .= ‘<li><a class="author">comment_post_ID ) . ‘#comment-‘ . $comment->comment_ID . ‘ »>’;
$comm .= get_avatar( $comment->comment_author_email, $avatar_size );
$comm .= get_comment_author( $comment->comment_ID ) . ‘</a> le’;
$comm .= get_comment_date( $comment->comment_ID );
$comm .= ‘<p>‘ . strip_tags( substr( apply_filters( ‘get_comment_text’, $comment->comment_content ), 0, $comment_len ) ) . ‘…</p></li>‘;
endforeach; else :
$comm .= ‘No comments.’;
endif;
echo $comm;
}
// Enable PHP in widgets
add_filter(‘widget_text’,’execute_php’,100);
function execute_php($html){
if(strpos($html, » ».$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}Deux codes trouvés ici et là, pour respectivement créer une fonction d’appel de commentaires et autoriser le php dans un widget txt…
Ce dernier semble dangereux (c’est ce que dit l’auteur) donc si quelqu’un peut transformer la première fonction en widget. MERCI DE M’AIDER 🙂
17 août 2015 à 9 h 55 min #996025Bonjour.
Ce plugin https://wordpress.org/plugins/recent-posts-widget-extended/ fait ce que tu veux et il est à jour.
🙂
17 août 2015 à 10 h 15 min #996026Bonjour,
Je n’ai pas de solution sans plugin, sinon il y a Decent Comment qui affiche la date, et il est à jour.
https://wordpress.org/plugins/decent-comments/
Bonne journée.18 août 2015 à 2 h 54 min #996027Merci Messieurs, ça semble effectivement difficile sans plugin et avec widget. En fait j’aurais pu appeler directement et manuellement la fonction précédente dans ma sidebar en bidouillant le template (sidebar.php)
Je viens de repartir du plugin existant ns recent comments, assez léger (sans js mais avec de petits css) mais ne présentant pas la date et je l’ai adapté en ajoutant ce qui manquait et en l’allégeant encore un peu.
Voici le code à copier coller dans un fichier appelé widget-recent-comments.php et à charger via le ftp dans un dossier wp-content/plugins/aww-recent-comments:
‘widget_ns’, ‘description’ => __( ‘Recent comments, with Avatars.’ , ‘widget-recent-comments’) );
$this->WP_Widget(‘aww-recent-comments’, __(‘AWW Recent Comments’, ‘widget-recent-comments’), $widget_ops);
$this->alt_option_name = ‘widget_ns’;
if ( is_active_widget(false, false, $this->id_base) )
add_action( ‘wp_head’, array(&$this, ‘widget_style’) );
add_action( ‘comment_post’, array(&$this, ‘flush_widget_cache’) );
add_action( ‘transition_comment_status’, array(&$this, ‘flush_widget_cache’) );
}
function widget_style() { ?>
<?php
}
function flush_widget_cache() {
wp_cache_delete('widget_ns', 'widget');
}
function widget( $args, $instance ) {
global $comments, $comment;
$cache = wp_cache_get('widget_ns', 'widget');
if ( ! is_array( $cache ) )
$cache = array();
if ( isset( $cache[$args['widget_id']] ) ) {
echo $cache[$args['widget_id']];
return;
}
extract($args, EXTR_SKIP);
$output = '';
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments', 'widget-recent-comments') : $instance['title']);
if ( ! $number = (int) $instance['number'] )
$number = 5;
else if ( $number $number, ‘status’ => ‘approve’ ) );
$output .= $before_widget;
if ( $title )
$output .= $before_title . $title . $after_title;
$output .= ‘<ul id="ns">‘;
if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= ‘<div class="avat">‘;
$output .= get_avatar($comment, $size) . ‘ ‘;
$output .= sprintf(__(‘%1$s dans </div><li class="aww-comment"> %2$s’, ‘widget-recent-comments’), get_comment_author(), ‘<a>comment_ID) ) . ‘ »>’ . get_the_title($comment->comment_post_ID) . ‘</a>‘);
$output .= ‘</br>‘ . get_comment_date() . ‘ ‘;
$output .= ‘</br></li>‘;
}
}
$output .= ‘</ul>‘;
$output .= $after_widget;
echo $output;
$cache[$args[‘widget_id’]] = $output;
wp_cache_set(‘widget_ns’, $cache, ‘widget’);
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance[‘title’] = strip_tags($new_instance[‘title’]);
$instance[‘number’] = (int) $new_instance[‘number’];
$instance[‘size’] = ( $new_instance[‘size’] flush_widget_cache();
$alloptions = wp_cache_get( ‘alloptions’, ‘options’ );
if ( isset($alloptions[‘widget_ns’]) )
delete_option(‘widget_ns’);
return $instance;
}
function form( $instance ) {
$title = isset($instance[‘title’]) ? esc_attr($instance[‘title’]) : »;
$number = isset($instance[‘number’]) ? absint($instance[‘number’]) : 3;
$size = isset($instance[‘size’]) ? absint($instance[‘size’]) : 40;
?>
<p><label for="get_field_id(‘title’); ?> »></label>
<input class="widefat" id="get_field_id(‘title’); ?> » name= »get_field_name(‘title’); ?> » type= »text » value= » » /></p>
<p><label for="get_field_id(‘number’); ?> »></label>
<input id="get_field_id(‘number’); ?> » name= »get_field_name(‘number’); ?> » type= »text » value= » » size= »3″ /></p>
<p><label for="get_field_id(‘size’); ?> »></label>
<input id="get_field_id(‘size’); ?> » name= »get_field_name(‘size’); ?> » type= »text » value= » » size= »3″ /></p>
<?php
}
}Il suffit ensuite d’activer le plugin et insérer le widget dans l’admin… (et ensuite suivre les mise à jour de wp pour voir si aucune des qq fonctions utilisées n’a été dépréciées)
En espérant que ça aide qqn.A bientôt pour de nouvelles recherches,
18 août 2015 à 4 h 30 min #996028✅ (au fait)
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.