我正在创建一个评论网站,我想在一个单独的页面上显示来自单个餐厅的客户评论(评论)。php。我会有一个链接,上面写着(阅读评论/添加你的评论)。
我创建了一个自定义评论模板,并将其命名为评论端。php,这就是我所拥有的:
<?php
/**
* Comments Template
*
*/
?>
<div id="comments-template" class="comments-side">
<div class="comments-wrap">
<div id="comments">
<?php if ( have_comments() ) : ?>
<?php do_atomic( \'before_comment_list\' );// supreme_before_comment_list ?>
<ol class="comment-list">
<?php $args = array(
\'walker\' => null,
\'max_depth\' => \'10\',
\'style\' => \'ul\',
\'callback\' => \'mytheme_comment\',
\'end-callback\' => null,
\'type\' => \'all\',
\'reply_text\' => \'Reply\',
\'length\' => \'10\',
\'page\' => \'\',
\'per_page\' => \'3\',
\'avatar_size\' => 32,
\'reverse_top_level\' => null,
\'reverse_children\' => \'\',
\'format\' => \'xhtml\', //or html5 @since 3.6
\'short_ping\' => false // @since 3.6
); ?>
<?php wp_list_comments( $args, $comments); ?>
</ol><!-- .comment-list -->
<?php endif; ?>
</div><!-- #comments -->
<?php $comment_args = array( \'fields\' => apply_filters( \'comment_form_default_fields\', array(
\'author\' => \'<div class="form_row clearfix">\' .
\'<input id="author" name="author" type="text" value="\' .
esc_attr( $commenter[\'comment_author\'] ) . \'" size="30"\' . @$aria_req . \' PLACEHOLDER="\'.__(\'Your name\',\'supreme\').\'"/>\' .
( $req ? \' <span class="required">*</span>\' : \'\' ) .
\'</div><!-- #form-section-author .form-section -->\',
\'email\' => \'<div class="form_row clearfix">\' .
\'<input id="email" name="email" type="text" value="\' . esc_attr( $commenter[\'comment_author_email\'] ) . \'" size="30"\' . @$aria_req . \' PLACEHOLDER="\'.__(\'Email Address\',\'supreme\').\'"/>\' .
( $req ? \' <span class="required">*</span>\' : \'\' ) .
\'</div><!-- #form-section-email .form-section -->\',
\'url\' => \'<div class="form_row clearfix">\' .
\'<input id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) . \'" size="30"\' . @$aria_url . \' PLACEHOLDER="\'.__(\'Website\',\'supreme\').\'"/>\'.\'</div>\')),
\'comment_field\' => \'<div class="form_row clearfix">\' .
\'<textarea id="comments" name="comment" cols="45" rows="8" aria-required="true" PLACEHOLDER="\'.__(\'Comments\',\'supreme\').\'"></textarea>\' .
( $req ? \' <span class="required">*</span>\' : \'\' ) .
\'</div><!-- #form-section-comment .form-section -->\',
\'comment_notes_after\' => \'\',
\'title_reply\' => __( \'Add a comment\', \'supreme\' ),
);
if(get_option(\'default_comment_status\') ==\'open\'){
comment_form($comment_args); } // Loads the comment form. ?>
</div><!-- .comments-wrap -->
</div><!-- #comments-template -->
但是,当我尝试转到注释模板时(
http://myurl.com/post-slug/comments-side/), 页面抛出404错误。我将permalinks更改为默认设置,并将其切换回/%postname%/但我仍然得到404。
如何使其正常工作?
我不知道这是否相关,但这就是我的职能。php注释:
function mytheme_comment($comment, $args, $depth) {
$GLOBALS[\'comment\'] = $comment;
extract($args, EXTR_SKIP);
if ( \'div\' == $args[\'style\'] ) {
$tag = \'div\';
$add_below = \'comment\';
} else {
$tag = \'li\';
$add_below = \'div-comment\';
}
?>
<<?php echo $tag ?> <?php comment_class(empty( $args[\'has_children\'] ) ? \'\' : \'parent\') ?> id="comment-<?php comment_ID() ?>">
<?php if ( \'div\' != $args[\'style\'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ($args[\'avatar_size\'] != 0) echo get_avatar( $comment, $args[\'avatar_size\'] ); ?>
<?php printf(__(\'<cite class="fn">%s</cite> <span class="says">says:</span>\'), get_comment_author_link()) ?>
</div>
<?php if ($comment->comment_approved == \'0\') : ?>
<em class="comment-awaiting-moderation"><?php _e(\'Your comment is awaiting moderation.\') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
<?php
/* translators: 1: date, 2: time */
printf( __(\'%1$s at %2$s\'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__(\'(Edit)\'),\' \',\'\' );
?>
</div>
<?php comment_text($comment_ID); ?>
<a href="comments-side/#comment-<?php comment_ID() ?>" class="comment-more">read more</a>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array(\'add_below\' => $add_below, \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\']))) ?>
</div>
<?php if ( \'div\' != $args[\'style\'] ) : ?>
</div>
<?php endif; ?>
<?php
}
这是我在单人餐厅里吃的东西。php显示“restaurants”帖子类型中每个帖子的最新评论
<div class="sidereviews clearfix">
<h3>Recent Reviews</h3>
<?php comments_template( \'/comments-side.php\', true ); // Loads the comments-side.php template. ?>
</div><!--/sidereviews-->