- Statut : non résolu
- Ce sujet contient 1 réponse, 1 participant et a été mis à jour pour la dernière fois par
Tche, le il y a 10 années et 10 mois.
-
AuteurMessages
-
26 août 2014 à 13 h 45 min #541259
Bonjour,
Ma configuration WP actuelle
– Version de WordPress : 3.9.2
– Version de PHP/MySQL : Wamp
– Thème utilisé : Twentyfourteen-child
– Extensions en place : akismet, super socializer, relevanssi, theme my login, transposh, user submitted post, contact 7 form
– Nom de l’hebergeur : wamp
– Adresse du site : localhostProblème(s) rencontré(s) : Voilà j’étais tout content de pouvoir ajouter un champ titre au formulaire de commentaire en ajoutant le code suivant à mon functions.php
/// Ajouter un titre aux commentaires
add_action( ‘comment_form_logged_in_after’, ‘additional_fields’ );
add_action( ‘comment_form_after_fields’, ‘additional_fields’ );
function additional_fields () {
echo ‘<p class="comment-form-title">‘.
‘<label for="title">‘ . __( ‘Titre (Je peux…)’ ) . ‘</label>‘.
‘<input id="title" name="title" type="text" size="30" tabindex="5" /></p>‘;
}
// Save the comment meta data along with comment
add_action( ‘comment_post’, ‘save_comment_meta_data’ );
function save_comment_meta_data( $comment_id ) {
if ( ( isset( $_POST[‘title’] ) ) && ( $_POST[‘title’] != ») )
$title = wp_filter_nohtml_kses($_POST[‘title’]);
add_comment_meta( $comment_id, ‘title’, $title );
}
// Add the comment meta (saved earlier) to the comment text
// You can also output the comment meta values directly to the comments template
add_filter( ‘comment_text’, ‘modify_comment’);
function modify_comment( $text ){
if( $commenttitle = get_comment_meta( get_comment_ID(), ‘title’, true ) ) {
$commenttitle = ‘<strong>‘ . esc_attr( $commenttitle ) . ‘</strong><br/>‘;
$text = $commenttitle . $text;
}
}
// Add an edit option to comment editing screen
add_action( ‘add_meta_boxes_comment’, ‘extend_comment_add_meta_box’ );
function extend_comment_add_meta_box() {
add_meta_box( ‘title’, __( ‘Comment Metadata – Extend Comment’ ), ‘extend_comment_meta_box’, ‘comment’, ‘normal’, ‘high’ );
}
function extend_comment_meta_box ( $comment ) {
$phone = get_comment_meta( $comment->comment_ID, ‘phone’, true );
$title = get_comment_meta( $comment->comment_ID, ‘title’, true );
$rating = get_comment_meta( $comment->comment_ID, ‘rating’, true );
wp_nonce_field( ‘extend_comment_update’, ‘extend_comment_update’, false );
?>
<p>
<label for="title"><?php _e( 'Comment Title' ); ?></label>
<input type="text" name="title" value="<?php echo esc_attr( $title ); ?> » class= »widefat » />
</p>
<?php
}
// Update comment meta data from comment editing screen
add_action( 'edit_comment', 'extend_comment_edit_metafields' );
function extend_comment_edit_metafields( $comment_id ) {
if( ! isset( $_POST['extend_comment_update'] ) || ! wp_verify_nonce( $_POST['extend_comment_update'], 'extend_comment_update' ) ) return;
if ( ( isset( $_POST['title'] ) ) && ( $_POST['title'] != '') ):
$title = wp_filter_nohtml_kses($_POST['title']);
update_comment_meta( $comment_id, 'title', $title );
else :
delete_comment_meta( $comment_id, 'title');
endif;
}J’étais aussi heureux de pouvoir modifier les textes du formulaire dans comment.php
<?php
/**
* The template for displaying Comments
*
* The area of the page that contains comments and the comment form.
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
/*
* If the current post is protected by a password and the visitor has not yet
* entered the password we will return early without loading the comments.
*/
if ( post_password_required() ) {
return;
}
?>
<div id="comments" class="comments-area">
<h2>* Je peux suivre ce voeu</h2>
<p>…et rester informé de toutes ses modifications. (Même sans le commenter)</p>
<?php if (function_exists('subscribe_reloaded_show')) subscribe_reloaded_show(); ?>
<?php
$aria_req = ( $req ? " aria-required='true'" : '' );
$args = array(
'id_form' => ‘commentform’,
‘id_submit’ => ‘submit’,
‘title_reply’ => __( ‘* Je peux apporter une solution’ ),
‘title_reply_to’ => __( ‘Je peux répondre à %s’ ),
‘cancel_reply_link’ => __( ‘Cancel Reply’ ),
‘label_submit’ => __( ‘Je le dis!’ ),
‘comment_field’ => ‘<p class="comment-form-comment"><label for="comment">‘ . _x( ‘Solution(s), critiques, témoignage:’, ‘noun’ ) .
‘</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true">‘ .
‘</textarea></p>‘,
‘must_log_in’ => ‘<p class="must-log-in">‘ .
sprintf(
__( ‘Il suffit de <a href="%s">se connecter</a> (ou s’inscrire) pour accéder au formulaire.’ ),
wp_login_url( apply_filters( ‘the_permalink’, get_permalink() ) )
) . ‘</p>‘,
‘logged_in_as’ => ‘<p class="logged-in-as">‘ .
sprintf(
__( ‘Connecté en tant que <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Me déconnecter?</a>‘ ),
admin_url( ‘profile.php’ ),
$user_identity,
wp_logout_url( apply_filters( ‘the_permalink’, get_permalink( ) ) )
) . ‘</p>‘,
‘comment_notes_before’ => ‘<p class="comment-notes">‘ .
__( ‘Your email address will not be published.’ ) . ( $req ? $required_text : » ) .
‘</p>‘,
‘comment_notes_after’ => ‘<p class="form-allowed-tags">‘ .
sprintf(
__( ‘You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s’ ),
‘ <code>' . allowed_tags() . '</code>‘
) . ‘</p>‘,
‘fields’ => apply_filters( ‘comment_form_default_fields’, array(
‘author’ =>
‘<p class="comment-form-author">‘ .
‘<label for="author">‘ . __( ‘Name’, ‘domainreference’ ) . ‘</label> ‘ .
( $req ? ‘<span class="required">*</span>‘ : » ) .
‘<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' /></p>‘,
’email’ =>
‘<p class="comment-form-email"><label for="email">‘ . __( ‘Email’, ‘domainreference’ ) . ‘</label> ‘ .
( $req ? ‘<span class="required">*</span>‘ : » ) .
‘<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' /></p>‘,
‘url’ =>
‘<p class="comment-form-url"><label for="url">‘ .
__( ‘Website’, ‘domainreference’ ) . ‘</label>‘ .
‘<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30" /></p>‘,
)
),
);
comment_form($args); ?>
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'twentyfourteen' ),
number_format_i18n( get_comments_number() ), get_the_title() );
?>
</h2>
<?php if ( get_comment_pages_count() > 1 && get_option( ‘page_comments’ ) ) : ?>
<nav id="comment-nav-above" class="navigation comment-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfourteen' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentyfourteen' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentyfourteen' ) ); ?></div>
</nav><!-- #comment-nav-above -->
<?php endif; // Check for comment navigation. ?>
<ol class="comment-list">
<?php
wp_list_comments( array(
'style' => ‘ol’,
‘short_ping’ => true,
‘avatar_size’=> 34,
)
);
?>
</ol><!-- .comment-list -->
<?php if ( get_comment_pages_count() > 1 && get_option( ‘page_comments’ ) ) : ?>
<nav id="comment-nav-below" class="navigation comment-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfourteen' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentyfourteen' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentyfourteen' ) ); ?></div>
</nav><!-- #comment-nav-below -->
<?php endif; // Check for comment navigation. ?>
<?php if ( ! comments_open() ) : ?>
<p class="no-comments"><?php _e( 'Comments are closed.', 'twentyfourteen' ); ?></p>
<?php endif; ?>
<?php endif; // have_comments() ?>
</div><!-- #comments -->Sans toucher du tout à
‘style’ => ‘ol’,
‘short_ping’ => true,
‘avatar_size’=> 34,
) ); ?>Et pourtant avec ces modifs le ni le titre du commentaire, ni son contenu n’apparaissent plus, une fois qu’il a été publié…. (alors qu’ils sont bien repris dans le base de données)
Quelqu’un aurait-il une idée de ce qui coince?
Un tout grand merci d’avance pour votre aide!!!
Thierry26 août 2014 à 16 h 30 min #968618Petit update,
En retirant ceci de functions.php:// Add the comment meta (saved earlier) to the comment text
// You can also output the comment meta values directly to the comments template
add_filter( ‘comment_text’, ‘modify_comment’);
function modify_comment( $text ){
if( $commenttitle = get_comment_meta( get_comment_ID(), ‘title’, true ) ) {
$commenttitle = ‘<strong>‘ . esc_attr( $commenttitle ) . ‘</strong><br />‘;
$text = $commenttitle . $text;
}
}Le commentaire publié apparait mais toujours sans le titre…
Je suis donc parti sur un autre tuto et j’ai ajouté ceci à functions.php pour modifier l’appel wp_list_comments…
// Update wp_comment_list
function mytheme_comment($comment, $args, $depth) {
$GLOBALS[‘comment’] = $comment; ?>
<li id= »li-comment-« >
<div id="comment-« >
<div class="comment-author vcard">
<?php echo get_avatar($comment,$size='48',$default='’ ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>‘), get_comment_author_link()) ?>
</div>
comment_approved == ‘0’) : ?>
<em></em>
<br />
<div class="commentmetadata"><a href="comment_ID ) ) ?> »></a></div>
<h3></h3>
<div class="reply">
$depth, ‘max_depth’ => $args[‘max_depth’]))) ?>
</div>
</div>
<?php
}Pour terminer, dans comments.php j’ai remplacé
‘ol’,
‘short_ping’ => true,
‘avatar_size’=> 34,
) ); ?>par:
pour appeler mon modèle de liste de commentaires.
Voilà, je me dis que ça pourra peut-être en aider d’autres et que si quelqu’un à des solutions plus directes il pourra les ajouter ci-dessous.
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.