Tìm Hiểu về Wordpress - part 27 - Pdf 16

247
</ol>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<! if comments are open, but there are no comments >
<p class="nocomments">Somebody say something!</p>
<?php else : // comments are closed ?>
<! if comments are closed >
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
That's all there is to it, really. Of course, like all things WordPress, there are
a gazillion different ways to customize things, change the design, enhance
functionality, and so on. Once you have threaded comments set up, they are easily
styled with the following CSS selectors:
.commentlist li.depth-1 {}
.commentlist li.depth-2 {}
.commentlist li.depth-3 {} /* and so on */
Reply-To for Non-JavaScript Users
To accommodate those without JavaScript, replace your crusty old “Leave a Comment” text with something
more dynamic by using this instead:
<?php comment_form_title('Leave a Reply', 'Leave a Reply to %s'); ?>
This tag will output “Leave a Reply” by default, but as soon as someone without JavaScript clicks to reply to
a comment, the page refreshes and the output changes to “Leave a Reply to Whoever.” You can customize
the text to whatever you want. The “%s” will dynamically output the name of the person being replied to.
Threaded Plugins
If your version of WordPress
does not support threaded
comments, upgrade. If
upgrading is not on the menu,
you can get threaded comments

adaptable, and flexible as possible.
Thanks to the “type” parameter of the wp_list_comments() template tag,
separating your comments, pingbacks, and trackbacks is a breeze. Here are some
examples to give you a general idea. Once you see the pattern, you can set things
up however you like.
Separate comments from both pingbacks and trackbacks
<h3>Comments</h3>
<ol class="comments">
<?php wp_list_comments('type=comment'); ?>
</ol>
<h3>Pingbacks/Trackbacks</h3>
<ol class="pingbacks-trackbacks">
<?php wp_list_comments('type=pings'); ?>
</ol>
Separate comments, pingbacks, and trackbacks
<h3>Comments</h3>
<ol class="comments">
<?php wp_list_comments('type=comment'); ?>
</ol>
<h3>Pingbacks</h3>
250
<ol class="pingbacks">
<?php wp_list_comments('type=pingback'); ?>
</ol>
<h3>Trackbacks</h3>
<ol class="trackbacks">
<?php wp_list_comments('type=trackback'); ?>
</ol>
And finally, here is the code required to separate comments from pingbacks and
trackbacks using the old-school, foreach loop:

<?php } ?>
<?php endforeach; ?>
<h3>Pingbacks/Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link(); ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>
You will inevitably want to customize the markup, template tags,
and other functionality, but the central technique is all there.
We are segregating the previous single comment loop with two
individual loops that target comments and ping/trackbacks,
respectively. Within each of these two loops, we are testing for the
comment type and only displaying the preferred type within
each loop.
Along the way, we season the script with some modest HTML
markup to keep things readable on the page. Once you establish
core functionality on your site, you should customize the code
according to your needs.
Keep 'em Separated
As you can see, displaying comments and ping/
trackbacks separately helps keep your comments
clean and organized. Otherwise, pingbacks and
trackbacks get mixed up in your comment thread
and ruin the conversation.
252
7.3.6 Eliminating Pingbacks and Trackbacks

Edit page.
Omit ping/trackbacks from the comments loop
Using the wp_list_comments tag to display your comments, simply set the “type”
parameter as described in section 7.3.2. With the following code, for example, no
pingbacks or trackbacks will be displayed – only comments:
<h3>Comments</h3>
<ol class="comments">
<?php wp_list_comments('type=comment'); ?>
</ol>
Delete the wp-trackback.php file from the root directory
This is a very effective way of permanently disabling pingbacks and trackbacks.
It is a totally safe thing to do, just remember to re-delete the file after
upgrading WordPress.
Globally disabling via plugin
To globally disable trackbacks only, we can use Viper007Bond’s Disable Trackbacks
plugin Since this is a very simple plugin, we can just add it to
our active theme’s functions.php file (code modified/formatted for clarity):
Save the Juice
Pingbacks may represent a
reciprocal linking affair, but
trackbacks are generally free
links to the referring site. Why
waste the juice on a site that
can't spare an actual link?
254
// Disable Trackbacks />class DisableTrackbacks {
// initialize plugin
function DisableTrackbacks() {
add_action('pings_open', array(&$this, 'pings_open'));
}

Globally disable pingbacks/trackbacks before a certain date
For this query, specify the ping_status as either open or closed. Also, specify the
date by editing the date, “2009-09-09”, to suit your needs.
UPDATE wp_posts SET ping_status = 'closed' WHERE post_date < '2009-09-09'
AND post_status = 'publish';
Complete, one-step discussion management
Given the queries described above, we may fashion the following “one-step” SQL
queries, perfect for complete, plugin-free discussion management:
Globally enable/disable all discussion: comments, pingbacks and trackbacks
For this query, specify the comment_status as either open, closed, or registered_only.
Also, specify the ping_status as either open or closed.
UPDATE wp_posts SET comment_status = 'open', ping_status = 'open'
WHERE comment_status = 'closed' AND post_status = 'publish';
Back that DB Up!
Before running any SQL
queries or doing any other work
on your database, remember to
make a backup copy or two.
The database stores all of
your information and data – it
would suck royally to lose it.
Quick and Easy
These SQL queries are perfect
for managing discussion a few
times a year without using
another plugin.
256
Globally enable/disable comments, pingbacks and trackbacks before a certain date
For this query, specify the comment_status as either open, closed, or registered_only.
Also, specify the ping_status as either open or closed. Finally, specify the date by


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status