0
这是我第一次尝试定制WP评论表单,这给我带来了一些麻烦。 理想情况下,我想要一个包含3个字段的评论表单:名称,位置和评论。 为了方便的是,我使用数组:php array not working
<?php comment_form(array(
'title_reply'=> 'Please feel free to share your home owning hopes and dreams.',
'fields' => apply_filters('comment_form_default_fields', $fields),
'label_submit' => 'Share',
));
?>
在评论列表,我想要的评论显示,只是下面有“名称|位置”
<div class="comment-content"><?php comment_text(); ?><?php comment_author(); ?> | <?php echo $comment_author_url ?> </div>
正如你所看到的在live site,它不是那样。任何想法,为什么这可能是?提示和洞察力表示赞赏。
的functions.php
<?php
if (! function_exists('twentyeleven_comment')) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own twentyeleven_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Twenty Eleven 1.0
*/
function twentyeleven_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
switch ($comment->comment_type) :
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e('Pingback:', 'twentyeleven'); ?> <?php comment_author_link(); ?><?php edit_comment_link(__('Edit', 'twentyeleven'), '<span class="edit-link">', '</span>'); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<div class="comment-content"><?php comment_text(); ?><?php comment_author(); ?> | <?php echo $comment_author_url ?> </div>
</article><!-- #comment-## -->
<?php
break;
endswitch;
}
endif; // ends check for twentyeleven_comment()
// Custom callback to list comments in the your-theme style
function custom_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
$GLOBALS['comment_depth'] = $depth;
?>
<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
<div class="comment-author vcard"><?php commenter_link() ?></div>
<div class="comment-meta"><?php printf(__('Posted %1$s at %2$s <span class="meta-sep">|</span> <a href="%3$s" title="Permalink to this comment">Permalink</a>', 'your-theme'),
get_comment_date(),
get_comment_time(),
'#comment-' . get_comment_ID());
edit_comment_link(__('Edit', 'your-theme'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'your-theme') ?>
<div class="comment-content">
<?php comment_text() ?>
</div>
<?php // echo the comment reply link
if($args['type'] == 'all' || get_comment_type() == 'comment') :
comment_reply_link(array_merge($args, array(
'reply_text' => __('Reply','your-theme'),
'login_text' => __('Log in to reply.','your-theme'),
'depth' => $depth,
'before' => '<div class="comment-reply-link">',
'after' => '</div>'
)));
endif;
?>
<?php } // end custom_comments
// Custom callback to list pings
function custom_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
<div class="comment-author"><?php printf(__('By %1$s on %2$s at %3$s', 'your-theme'),
get_comment_author_link(),
get_comment_date(),
get_comment_time());
?></div>
<?php if ($comment->comment_approved == '0') _e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'your-theme') ?>
<div class="comment-content">
<?php comment_text() ?>
</div>
<?php } // end custom_pings
// Produces an avatar image with the hCard-compliant photo class
function commenter_link() {
$commenter = get_comment_author_link();
if (ereg('<a[^>]* class=[^>]+>', $commenter)) {
$commenter = ereg_replace('(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter);
} else {
$commenter = ereg_replace('(<a)/', '\\1class="url "' , $commenter);
}
$avatar_email = get_comment_author_email();
$avatar = str_replace("class='avatar", "class='photo avatar", get_avatar($avatar_email, 80));
echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
} // end commenter_link
if (!function_exists('iweb_reverse_comments')) {
function iweb_reverse_comments($comments) {
return array_reverse($comments);
}
}
add_filter ('comments_array', 'iweb_reverse_comments');
// custom comment field
function my_fields($fields) {
$fields['Location'] = '';
return $fields;
}
add_filter('comment_form_default_fields','my_fields');
?>
share.php
<?php
/*
Template Name: Share
*/
?>
<?php get_header(); ?>
<div class="content-left">
<?php comments_template(); ?>
</div><!-- end content-left -->
<div class="content-right">
<?php wp_list_comments(array('callback' => 'twentyeleven_comment')); ?></ul>
</div><!-- end content-right -->
<?php get_footer(); ?>
对不起,正如我提到的,我对此仍然很陌生。我通过http://www.php.net/搜索,没有找到如何echo.exit方向。你能提供一个例子吗?谢谢。 – AMC
我在试图帮助你不要嘲笑你,反正祝你好运。 – mbouzahir
是的,我知道你在帮忙!谢谢你。我只是在看你是否能够更深入地解释一下。 – AMC