1. Trang chủ
  2. » Công Nghệ Thông Tin

Tìm Hiểu về Wordpress - part 29 doc

10 344 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

267 3. Your loop should now contain the following (along with other template tags, markup, etc.): <?php foreach ($comments as $comment) : ?> <?php comment_text(); ?> <?php if ($comment->comment_approved == '0') : ?> <p class="moderation">Your comment is awaiting moderation.</p> <?php endif; ?> <?php endforeach; ?> That’s all there is to it! Season to taste and enjoy your site’s improved usability! 7.4.7 Moderation Links in the Theme Itself As described in Chapter 5.3.4 (Extending WordPress), adding some easy admin buttons is a great way to improve the comment-moderation process for your site. In addition to managing comments through the WordPress Comments Admin area, it is also helpful to have some easy admin buttons located next to the comments as they appear on your blog. Here is an easy way to add “spam” and “delete” links next to each comment whenever you are logged in as Administrator. Having access to spam and delete buttons next to each comment makes it super-easy to clean up missed spam, scummy trackbacks, and other garbage. I am continually scouring my old posts’ comments and weeding out junk, which for me is always easier to see from the actual post pages themselves. Having quick and easy access to spam and delete buttons has made my comment management routine considerably easier. To add this functionality, we take advantage of the functions.php file by adding the following script: <?php // spam & delete links for all versions of WordPress function delete_comment_link($id) { 268 if (current_user_can('edit_post')) { echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?a ction=cdc&c='.$id.'">Delete</a> '; echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?a ction=cdc&dt=spam&c='.$id.'">Spam</a>'; } } ?> Place this function in your theme’s functions.php file, and then call the function by adding the following code to the desired location in your comments.php file: <?php delete_comment_link(get_comment_ID()); ?> And that’s all there is to it! Depending on the placement of the function call, your comments area should now feature quick and easy “spam” and “delete” buttons next to each individual comment. Even better, this improved function is version-independent, backwards-compatible, and thus will work for any version of WordPress. 7.4.8 Display Comment, Ping/Trackback Counts One more trick before we dig into optimization. Here is a way to easily display the number of comments, pingbacks, and trackbacks for each of your posts. Open your theme’s single.php file and add the following parameters to your comments_ template() tag: <?php comments_template('/comments.php', true); ?> Then to display the counts, simply use any of the following snippets in your comments template: 269 <?php global $wp_query; // this line required for any of the following ?> <?php // pingback and trackback count echo count($wp_query->comments_by_type['pings']); ?> <?php // trackback count echo count($wp_query->comments_by_type['trackback']); ?> <?php // pingback count echo count($wp_query->comments_by_type['pingback']); ?> <?php // comment count echo count($wp_query->comments_by_type['comments']); ?> 7.5.1 Optimizing the Comment Form As we improve the quality of our readers’ comments, let’s not forget about the comment form itself. There are many ways to improve the functionality and appearance of your comment form, including adding a preview feature, rich-text editor, and anti-spam functionality. Let’s dig in! 7.5.2 Set up Comment Previews Encourage your visitors to contribute to the conversation by helping them preview their comments before submission. By adding a comment-preview feature to your comment area, you provide readers with a powerful tool for eliminating Unstyled Forms Even very well-marked-up forms look like crap without CSS. Whaddyagonnado? Just Numbers Each of these tags outputs a number, namely the number of pings, trackbacks, pingbacks, and comments, respectively. WordPress 3.0 makes it easier than ever to include comment forms in your themes. Simply add the following tag to your comments.php file: <?php comment_form(); ?> Learn more about this tag at the WP Codex: http://digwp.com/u/498 Drop-Dead Easy Comment Forms 270 errors, reducing noise, and increasing quality. And best of all, adding comment- preview to your site is as easy as installing and configuring one of these plugins: • Ajax Comment Preview http://digwp.com/u/2 Provides an excellent Ajax-powered comment-preview plugin that works and feels great. Admin Options page lets you specify formatting options. • Ajax Force Comment Preview http://digwp.com/u/194 This plugin takes the utility of comment previews one step further by actually “forcing” commentators to preview their comments before submission. The plugin takes advantage of Ajax to avoid the need for a page refresh. Features built-in anti-spam functionality. • jQuery Comment Preview WordPress Plugin http://digwp.com/u/40 jQuery Comment Preview uses the jQuery library to generate built-in comment previews that do not require refreshing the page. Includes Admin Options page. • Live Comment Preview http://digwp.com/u/39 Live Comment Preview provides a “smooth live preview as you type.” This cool plugin makes live comment previews super easy – simply activate and enjoy. No Ajax required – works completely in the browser. • Really Simple Live Comment Preview http://digwp.com/u/41 A do-it-yourself tutorial that has received a lot of attention. The author keeps the article updated with the latest code and improvements, so if you need to implement a custom live-comment-preview solution, be sure to check it out. • Filosofo Comments Preview http://digwp.com/u/42 This well-built plugin works great with many WordPress themes and even works with WordPress-2.7’s new threaded comments feature. Includes Admin Options page for complete control over appearance and functionality. 7.5.3 Rich-Text Editors for Comments Out of the box, most WordPress themes provide a plain <textarea> for comments. This may work fine for savvy users who are familiar with a bit of HTML to add some 271 structure to their comments, but what about the average visitor who may not realize that such markup is possible. Fortunately, there are many options available for enabling your visitors to style their comment with simple markup using a rich-text editor. Let’s look at some of the best rich-text editors and plugins available for your comment form: • TinyMCEComments http://digwp.com/u/46 TinyMCEComments transforms your comment textarea into a full-featured WYSIWYG rich-text editor using WordPress’ bundled TinyMCE library (WordPress 2.0 and up). • TinyMCE http://digwp.com/u/47 TinyMCE is a popular open-source rich-text editor that is easy to integrate with your site. Highly customizable with themes and plugins. International language support, multiple browser support, Ajax support, and more. One of the best. Include Comments on Non-Single Pages Normally, WordPress will only display your comments template file, comments.php, when called from your theme’s single.php or any page.php file. This makes it possible to display comments on single posts and pages, but for archive views such as categories and indexes, you need to add a variable into the mix. Here’s how to display a comments template in any archive or index page. Replace your regular comments_template() tag – you know, the tag used to call your comments.php file – with this one: <?php global $withcomments; $withcomments = true; comments_template("/custom-comments.php"); ?> This will include the file named “custom-comments.php” and use its contents to display your comments. Nice! Alternately, if you are only displaying a single post on, say, your index page, you can simply include your comments template within the loop: <?php while (have_posts()) : the_post(); ?> <?php comments_template(); ?> <?php endwhile; ?> 272 • CKEditor http://digwp.com/u/48 CKEditor (recently changed from FCKEditor) is another popular open-source rich-text editor that is easy to integrate with your site. This awesome editor includes image-uploading, layout templates, custom styles, and even Adobe AIR support. Works and looks great in all modern browsers. Four stars! • WidgEditor http://digwp.com/u/49 WidgEditor is an easy-to-use open-source rich-text editor by Cameron Adams. This is not a plugin, but is a breeze to implement. Uses clean, easy-to-read JavaScript that degrades gracefully. • MarkItUp! http://digwp.com/u/50 MarkItUp! is a rich-text editor built on top of jQuery. Includes Ajax live preview, keyboard-shortcut support, and weighs only 6.5kb. An excellent solution for transforming any HTML textarea into a full-featured WYSIWYG text editor. • Damn Small Rich Text Editor http://digwp.com/u/51 Damn Small Rich Text Editor is a free, lightweight rich-text editor designed to work with jQuery and PHP. Includes image-uploading capabilities and is plugin- enabled. • WMD: The WYSIWYM Markdown Editor http://digwp.com/u/52 “What You See Is What You Mean” uses the Markdown language to mark up comments, which then transforms into HTML when the comment is saved. Comes with a nice editor bar as well as automatic live comment previews. 7.5.4 Adding Comment Quicktags One of the best ways to enhance the functionality of WordPress comments is to implement comment quicktags. Quicktags are JavaScript buttons included with the comment form that provide shortcuts to a variety of common markup elements. While typing their comments, users may want to use some bold or emphasized text, or maybe even drop a killer blockquote or a few lines of code. Comment quicktags enable commentators to format their comment with the appropriate markup easily with the click of a button. It’s a great feature that makes Rich Text Editors For more RTE choices, check out " Rich-Text Editors for 2010 and Beyond" at Six Revisions: http://digwp.com/u/496 273 leaving a comment so much fun. Sound good? Here are some comment-quicktag plugins to make it happen: • LMB^Box Comment Quicktags http://digwp.com/u/43 The LMB^Box Comment Quicktags plugin adds a Quicktag Toolbar directly above the comment form’s text area. The LMB^Box Quicktag Toolbar looks and functions exactly like the toolbar used in the WordPress Admin area, and may be styled to fit your site’s design. The toolbar provides quicktags for strong/ bold, em/italic, code, blockquote, and links tags by default, and the set of buttons is completely configurable via its Admin Options page. • Comment Quicktags http://digwp.com/u/44 Inserts an expandable quicktag toolbar above the WordPress comment form. You can customize the default CSS styles and add your own (X)HTML buttons, all from within a handy admin interface. Very nice. Display Comments in Descending Order By default, WordPress displays comments in chronological order: oldest comments first, newest comments last. To reverse this order, we can take advantage of PHP’s awesome array_reverse function. Here’s how: 1. Place the following code directly before your comment loop: <?php $comments = array_reverse($comments, true); ?> 2. Your comment loop should now look similar to this: <?php $comments = array_reverse($comments, true); ?> <?php foreach ($comments as $comment) : ?> <?php comment_author_link(); ?> <?php comment_text() ?> <?php endforeach; ?> That’s it! Your comments are displayed in reverse chronological order. 274 • Comment Form Quicktags http://digwp.com/u/45 This plugin inserts quicktags of the admin page to the upper part of textarea of the comment form. Provides easy tag configuration via the WordPress Admin. • Comment Quicktags Reloaded http://digwp.com/u/195 A slightly modified version of Owen Winkler’s Comment Quicktags plugin. If the original Comment Quicktags plugin is breaking your theme, try this version. 7.5.5 Comment Management and Spam Prevention Properly managing your comments can be as time-consuming as it is important. Sites with carefully managed comments sections are miles apart from sites that don’t. But it takes time, patience, and a good amount of attention to detail. Fortunately, when it comes to monitoring, moderating, and pruning comments, there are plenty of awesome plugins to help automate, improve, and enhance the process of filtering out spam and encouraging comments. We explore some of these tools in the final three sections of this chapter. 7.6.1 Controlling Comment Spam Ahh yes. The wonderful world of comment spam. By now, we assume that everyone is well-acquainted with the never-ending and utterly hellish spam battle. It rages constantly, with desperate Viagra and Cialis spammers seeking every opportunity to flood your otherwise pristine comments area with a truckload of their stinky garbage. Eww… Fortunately, all of the smart people are on our side, and there are many talented developers who continue to fight spam on the front lines. Fortunately, because of the popularity of WordPress, we enjoy a vast arsenal of effective anti-spam techniques for our sites. Let’s explore some of the best. 275 7.6.2 WordPress’ Built-In Anti-Spam Functionality With all of the excellent plugins available, many users don’t realize that WordPress provides some powerful tools for controlling spam right out of the box. Within the Discussion page of the WordPress Admin area, there are several options that are useful for controlling comments and preventing spam. Let’s take a quick look at each these options. • Default Article Settings - If you don’t need comments on your site, disable them. Completely disabling comments is a sure-fire, bulletproof way to eliminate all comment spam. • Users must be registered and logged in to comment - One way to allow comments but eliminate 90% (or more) of spam is to require the user to be registered and logged-in to your site before commenting. • Before a comment appears - An administrator must always approve the comment. If you have the time, this is another good way to ensure that no spam comments appear on your site. • Before a comment appears - Comment author must fill out name and e-mail. This may not do much for fighting spam, but it will discourage some of the lazier folks from commenting. No Plugins, No Spam It’s true. By carefully crafting your WordPress blog’s built-in comment settings, it is entirely possible to run a virtually spam-free site with absolutely no plugins whatsoever. – Not even Akismet. Read more at: http://digwp.com/u/416 276 • Before a comment appears - Comment author must have a previously approved comment. This is an effective way to prevent spam, although it does require some time on busier sites. • Auto-close Comments - Spammers often target older posts. Auto-closing comments on old posts helps reduce overall spam. • Hold a comment in the queue if it contains “x” or more links - As it says, this is a great way to screen any comments that have too many links. How many is up to you. • Comment Moderation Blacklist - This is a regular-expression blacklist of terms that will kick suspect comments into the moderation queue. Load this puppy up with all your favorite spam words – cialis, xanax, vicodin, viagra, etc. – and gain more control over your site’s comments. • Comment Spam Blacklist - Similar to the Moderation Blacklist, the Spam Blacklist features a list of regular expressions that will throw the comment into the spam bin. Be careful of the words that you include in this list, because anything that matches is essentially discarded. 7.6.3 Anti-Spam Plugins for WordPress • Akismet http://digwp.com/u/95 One of the best. Requires registration key. Easy to use. Bundled with WordPress. Excellent spam protection. ‘Nuf said. • Defensio Anti-Spam http://digwp.com/u/96 Advanced spam-filtering web-service that adapts to your blog’s behavior. Features statistics, feeds, and spam counters. Not to be used with any other anti-spam plugins. If Akismet isn’t cutting it for you, try Defensio. • Peter’s Custom Anti-Spam http://digwp.com/u/97 CAPTCHA-based anti-spam plugin. Forces all commentators to identify a random word before comment submission. Words are displayed as images and are completely customizable. Blacklist Ninja For a highly effective, custom blacklist of regular expressions for your site’s Comment Moderation or Spam Blacklist, drop by Perishable Press and grab a copy: http://digwp.com/u/196 . into a full-featured WYSIWYG rich-text editor using WordPress bundled TinyMCE library (WordPress 2.0 and up). • TinyMCE http://digwp.com/u/47 TinyMCE is a popular open-source rich-text editor. http://digwp.com/u/49 WidgEditor is an easy-to-use open-source rich-text editor by Cameron Adams. This is not a plugin, but is a breeze to implement. Uses clean, easy-to-read JavaScript that degrades. of the popularity of WordPress, we enjoy a vast arsenal of effective anti-spam techniques for our sites. Let’s explore some of the best. 275 7.6.2 WordPress Built-In Anti-Spam Functionality With

Ngày đăng: 04/07/2014, 21:20

Xem thêm: Tìm Hiểu về Wordpress - part 29 doc

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN