Hướng dẫn tạo themes cho wordpress part 9 - Pdf 16

Chapter 5
85
There's more
The number of parameters available to customize your comment's display is vast and varied.
Let's look at some of the important ones and the interesting things you can do with only a few
characters of code.
Separating comments and trackbacks
Comments on blog posts are generally left by a person with an opinion on the post in question.
Trackbacks occur when another blog links to a particular post or page. By default, WordPress
displays these different types of post commentary together, with comments and trackbacks
occurring side by side.
One of the easiest and most useful modications to make to your post comment listings is to
separate these two items. You can do this using only one parameter. Replace the code from
the recipe above with the following:
<h3>Trackbacks</h3>
<ol class="commentlist">
<?php wp_list_comments(array('type'=>'pings')); ?>
Comments
86
</ol>
<h3>Comments</h3>
<ol class="commentlist">
<?php wp_list_comments(array('type'=>'comment')); ?>
</ol>
You can see here that you're using the type parameter for the wp_list_comments function
to only output comments of a certain type in each list. You also added some headers to
indicate the type of content to follow. You can see the resulting output as follows:
Changing the Avatar size
One of the things that you'll want to customize is the avatar size displayed next to comments.
By default, the size is set to 32 pixels square. For a lot of themes, this is just not enough. To
change the size of the avatar, you simply change the avatar_size parameter as follows:

based on the parameters passed to it. In the previous example, ve comments are being
requested, and get_comments is allowed to otherwise use the default options for the
function. This leads to the ve latest comments being fetched, regardless of the post on
which they were made.
wp_list_comments, described in the previous recipe, takes an optional second parameter,
which must be an array of comment objects. Here we are passing the comments returned from
get_comments along with an empty array, in order to ensure that wp_list_comments uses
its default display parameters.
Comments
88
There's more
The get_comments function takes a wide variety of parameters that can be used to affect
the comment results that are returned. You should be familiar with some of the most
commonly-used ones, which are outlined in the following sections.
Getting only certain comment types
By default, get_comments returns comment objects regardless of type. However, you can
easily change this by passing a single parameter. This might be useful when you want to get the
last ve trackbacks, or if you're using a custom comment type to represent some information
(like user reviews or something similar).
<?php $trackbacks = get_comments(array('type'=>'pings')); ?>
Getting only comments for a particular post
If you specify a post id when calling get_comments, you can retrieve comments for that
post only. The following code will do just that, specifying a post ID of 34:
<?php
$post_34_comments = get_comments(array('post_id'=>34));
?>
Available parameters
While we've touched on a couple of the available parameters for get_comments, there are
many more available. You can nd the complete list of all of the get_comments parameters
at />Highlighting the post author's comments

id="comment-48">
<! Comment Content >
</li>
<li class="pingback even thread-even depth-1"
id="comment-47">
<! Comment Content >
</li>
<li class="comment byuser comment-author-admin
bypostauthor odd alt thread-odd thread-alt
depth-1"
id="comment-59">
<! Comment Content >
</li>
</ol>
Comments
90
If a comment is made by the post author, then the containing element is assigned a class
of bypostauthor. In the above CSS snippet, elements with both the comment and
bypostauthor classes are assigned a different background color and text color than
the regular comment containers. You can see this in action in the following screenshot:
See also
Displaying comments on a post
Alternating the style for comments
Comments are often displayed in a list form, with each comment being displayed one after
another. Each comment includes the same title, a similar-looking avatar, and paragraphs of
comment content. The format can get monotonous and cause eye strain and confusion in
users who nd it hard to differentiate between comments. Luckily, reconciling this issue is a
simple matter of adding a small amount of styling using CSS. Due to the semantic nature of
comment HTML output by WordPress, this is a snap.


straightforward to implement the correct display of comment threads.
How to do it
First, you must enable comments on a post and display them properly. Follow the Displaying
a comment form on a post recipe to make sure that your comment form shows up and that
comments on particular posts are displayed in a list.
Next, open your theme's
header.php le and place the following code above your call to
wp_head. This code enables the comment reply JavaScript functionality, allowing your
users to easily and quickly form threaded conversations.
<?php
if( is_singular() ) {
wp_enqueue_script( 'comment-reply' );
}
?>
Next, you need to add the appropriate styles that will effectively display your conversations.
Open your theme's stylesheet, style.css, and insert the following style declaration:
.children {
margin-left: 10px;
}
Now refresh a single post view on your blog and add a threaded comment by clicking on the
reply button for a comment and lling in the appropriate information. After you submit the
comment, you should see something that looks like the following, depending on your styles:

Chapter 5
93
How it works
The default wp_list_comments function displays threaded comments to a depth specied
in the WordPress administrative back-end. The markup technique used is to nest lists inside
of list items in order to produce the threaded effect.
By enqueuing the appropriate JavaScript le, you're allowing WordPress's built-in comment reply


Nhờ tải bản gốc
Music ♫

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