One of the best things about wordpress is the built-in social aspect provided by comments. Getting your comment section right can be very important to any website, including ours. Over the years we’ve experimented with various comment plugins including Disqus and more recently Jetpack. However, nous avons toujours fini par ramener les choses dans la maison pour la gestion, performance and privacy reasons. When I moved back from Jetpack comments I really missed some of the slick features provided by Jetpack, both the social-network logins and the general slick styling. Anyway, to cut a long story short I finally had time today to take a good look at how wordpress “does” comments and figure out a way to build an in-house system which looks nice and slick like the comment interface provided by jetpack. Best of all its surprisingly simple and does things the “proper” way…
Première - pour faire face à l'aspect «social», Je l'ai eu recours à un plugin appelé WordPress Social Connexion par Miled. There are several “social login” plugins, mais cette version (contrairement aux autres) keeps everything totally in-house. It is a bit more work to configure, mais pour le bénéfice à notre vie privée des visiteurs pour cette seule vaut bien la peine.
Ensuite a été de déterminer comment modifier la fonction intégrée dans le formulaire de commentaire wordpress (fun-Nily assez appelé comment_form()). Je vais vous donner plus de détails plus tard si quelqu'un en fait la demande, pour l'instant juste trouver le rel-ev-fourmi code ci-dessous ...
comments.php (dans le dossier de thème)
<!-- You can start editing here. --> <?php if ( comments_open() ) : ?> <section id="respond" class="respond-form"> <?php comment_form(); ?> <script> document.getElementById('hidden-form-area').style.display = 'none'; function myFunction() { document.getElementById('hidden-form-area').style.display = 'block'; } </script> </section> <?php endif; // if you delete this the sky will fall on your head ?>
functions.php (dans le dossier de thème)
function my_fields($fields) { $fields['author'] = '<p class="comment-form-author"><input type="text" name="author" id="author" size="22" tabindex="1" placeholder="Name (required)" /></p>'; $fields['email'] = '<p class="comment-form-email"><input type="text" name="email" id="email" size="22" tabindex="2" placeholder="E-mail (required - never shared with anyone)" /></p>'; $fields['url'] = '<p class="comment-form-url"><input type="text" name="url" id="url" size="22" tabindex="2" placeholder="Website" /></p>'; return $fields; } add_filter('comment_form_default_fields','my_fields'); function remove_notice($defaults) { $defaults['comment_notes_before'] = ''; $defaults['comment_notes_after'] = ''; return $defaults; } add_filter( 'comment_form_defaults', 'remove_notice' ); function remove_textarea($defaults) { $defaults['comment_field'] = ''; return $defaults; } add_filter( 'comment_form_defaults', 'remove_textarea' ); function add_textarea() { echo '<p class="comment-form-comment"><textarea id="comment" name="comment" placeholder="Enter your comment here..." onfocus="myFunction()"></textarea></p><div id="hidden-form-area">'; } add_action( 'comment_form_top', 'add_textarea', 1 ); function add_hideend() { echo '</div>'; } add_action( 'comment_form_after', 'add_hideend' );
Pense que nous avons manqué quelque chose? Faites-nous savoir en commentant ci-dessous. Si vous souhaitez vous abonner s'il vous plaît utiliser le lien d'abonnement dans le menu en haut à droite. Vous pouvez également partager avec vos amis en utilisant les liens sociaux ci-dessous. À votre santé.
Merci pour les codes, ils sont utiles ...