一个关于WordPress的最好的事情是发表了内置的社交方面。让您的注释部分权可以到任何网站很重要, 包括我们在内。多年来,我们已经尝试了各种评论插件,包括Disqus和最近的Jetpack。然而, 我们一直都结束了把东西放回房子管理, 性能和隐私的原因。当我从Jetpack的意见搬回我真的错过了一些通过的Jetpack提供的光滑特点, 无论是社交网络的登录和一般光滑的造型。无论如何, 削减长话短说,我终于有今天的时间采取在WordPress的是如何“做”的意见很好看,并想出一个办法来建立一个内部系统看上去很光滑,并通过类似传送插座提供的评论接口。最重要的是其令人惊讶的简单和做事的“正确”的方式...
First — to deal with the “social” aspect, I’ve resorted to a plugin called WordPress Social Login 经过 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.
Next up was figuring out how to change the built-in wordpress comment form function (funnily enough called comment_form()). I’ll provide more detail later if anyone requests it, for now just find the relevant code below…
的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 (必需的)” /></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]
你怎么看? 请给我们一个评论如下! 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.
感谢您的代码, 他们是有用的?