Skip to content

Instantly share code, notes, and snippets.

@hbsnow
Last active December 12, 2015 08:59
Show Gist options
  • Save hbsnow/4748401 to your computer and use it in GitHub Desktop.
Save hbsnow/4748401 to your computer and use it in GitHub Desktop.
wordpressのスレッド表示対応 comment.php
<section id="reply">
<h2>Comment</h2>
<?php
$u_comments = get_comments(array(
"post_id" => $post->ID,
"status" => "approve",
"type" => "comment"
));
if($u_comments):
wp_list_comments(array(
"type" => "comment",
"style" => "div",
"callback" => "custom_comments"//function.phpに記述
));
else: ?>
<p>コメントはありません。</p>
<?php endif;?>
<section id="respond">
<h3><?php comment_form_title("Leave a Reply", "Leave a Reply to %s"); ?></h3>
<?php if(comments_open()): ?>
<?php if(get_option("comment_registration") && !$user_ID ): ?>
<p><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.'), get_option("siteurl")."/wp-login.php?redirect_to=".urlencode(get_permalink())); ?></p>
<?php else: ?>
<p class="cancel_comment"><?php cancel_comment_reply_link("Close"); ?></p>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" name="commentform" id="commentform">
<fieldset>
<?php if($user_ID): ?>
<p><a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>でログインしています。(<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout">ログアウト</a>)</p>
<dl>
<?php else: ?>
<p>名前・メールアドレスは任意です。メールアドレスは公開されません。</p>
<dl>
<dt><label for="author">name</label></dt>
<dd><input type="text" id="author" name="author" value="<?php echo $comment_author; ?>"></dd>
<dt><label for="email">mail</label></dt>
<dd><input type="text" id="email" name="email" value="<?php echo $comment_author_email; ?>"></dd>
<dt><label for="url">url</label></dt>
<dd><input type="text" id="url" name="url" value="<?php echo $comment_author_url; ?>"></dd>
<?php endif; ?>
<dt><label for="comment">comment</label></dt>
<dd><textarea name="comment" id="comment" cols="40" rows="8">コメントをどうぞ</textarea>
</dl>
<p><input name="submit" type="submit" id="submit" tabindex="6" value="Post"></p>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>">
<?php
// />を>に置き換える
ob_start();
comment_id_fields();
$comment_id_field_action = ob_get_contents();
ob_end_clean();
echo ereg_replace("\x20/>", ">", $comment_id_field_action);
do_action("comment_form", $post->ID); ?>
</fieldset>
</form>
<?php endif; ?>
<?php else :?>
<p>コメントは締め切られました。</p>
<?php endif; ?>
</section>
</section>
<section id="ping">
<h2>Trackback &amp; Pingback</h2>
<?php
$pings = get_comments(array(
"post_id" => $post->ID,
"status" => "approve",
"type" => "pings",
));
if($pings):
wp_list_comments(array(
"type" => "pings",
"callback" => "custom_pings"
));
else: ?>
<p>トラックバック、ピンバックはありません。</p>
<?php endif;?>
</section>
function custom_comments($comment, $args, $depth){
$GLOBALS["comment"] = $comment; ?>
<div <?php comment_class(); ?>>
<article id="comment-<?php comment_ID() ?>">
<header>
<ul class="commentinfo">
<li class="comment_author"><?php if($comment->comment_author){echo $comment->comment_author;}else{echo "anonymity#", comment_ID();} ?></li>
<?php if($comment->comment_approved == '0'): ?>
<li><?php _e('Your comment is awaiting moderation.') ?></li>
<?php endif; $date = new DateTime($comment->comment_date); ?>
<li><time><?php echo $date->format('Y-m-d'); ?></time></li>
</ul>
</header>
<div class="comment_entry"><?php comment_text() ?></div>
<?php
$comment_reply_link_array = array_merge($args, array(
"reply_text" => "Reply",
"depth" => $depth,
"max_depth" => $args["max_depth"]
));
if(get_comment_reply_link($comment_reply_link_array)): ?>
<footer>
<p><?php comment_reply_link($comment_reply_link_array); ?></p>
</footer>
<?php endif; ?>
</article>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment