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, 我々は常に管理のために戻って家の中のものを持って来ることになったきた, 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…
First — to deal with the “social” aspect, I’ve resorted to a plugin called WordPress Social Login by Miled. There are several “social login” plugins, but this version (unlike the others) keeps everything totally in-house. It is a bit more work to configure, but for the benefit to our visitors privacy alone this is well worth it.
次は、組み込みのWordPressのコメントフォーム機能を変更する方法を考え出すした (楽しいnily十分呼ばcomment_form()). 誰もがそれを要求した場合は、後で詳しく説明しますよ, 今すぐ下REL-EV-ANTのコードを見つけるために...
comments.php (テーマフォルダ内の)
[PHP]
<!– You can start editing here. –>
<?PHPの場合 ( comments_open() ) : ?>
<section id=“respond” class=“respond-form”>
<?php comment_form(); ?>
<スクリプト>
document.getElementById(‘hidden-form-area’).style.display = ‘none’;
function myFunction()
{
document.getElementById(‘hidden-form-area’).style.display = ‘block’;
}
</スクリプト>
</セクション>
<?PHP endifの; // if you delete this the sky will fall on your head?>
[/PHP]
のfunctions.php (テーマフォルダ内の)
[PHP]
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’ );
[/PHP]
コードをありがとう, 彼らは便利です...