我想在侧边栏上显示特定页面的注释表单。
大致是这样的。
<小时>
我试着从评论中修改。php并将其放在提要栏上。php。
但什么都没有出现。请帮忙?
<?php $aspirasi = get_post(2); ?>
<?php if ( \'open\' == $aspirasi->comment_status ) : ?>
<div id="respond">
<h3><?php comment_form_title( __(\'Post a Comment\', \'newtheme\'), __(\'Post a Reply to %s\', \'newtheme\') ); ?></h3>
<div class="formcontainer">
<form id="commentform" action="<?php echo get_option(\'siteurl\'); ?>/wp-comments-post.php" method="post">
<?php if ( $user_ID ) : ?>
<p id="login"><?php printf(__(\'<span class="loggedin">Logged in as <a href="%1$s" title="Logged in as %2$s">%2$s</a>.</span> <span class="logout"><a href="%3$s" title="Log out of this account">Log out?</a></span>\', \'newtheme\'),
get_option(\'siteurl\') . \'/wp-admin/profile.php\',
wp_specialchars($user_identity, true),
wp_logout_url(get_permalink()) ) ?></p>
<?php else : ?>
<p id="comment-notes"><?php _e(\'Your email is <em>never</em> published nor shared.\', \'newtheme\') ?> <?php if ($req) _e(\'Required fields are marked <span class="required">*</span>\', \'newtheme\') ?></p>
<div id="form-section-author" class="form-section">
<div class="form-label"><label for="author"><?php _e(\'Name\', \'newtheme\') ?></label> <?php if ($req) _e(\'<span class="required">*</span>\', \'newtheme\') ?></div>
<div class="form-input"><input id="author" name="author" type="text" value="<?php echo $comment_author ?>" size="30" maxlength="20" tabindex="3" /></div>
</div><!-- #form-section-author .form-section -->
<div id="form-section-email" class="form-section">
<div class="form-label"><label for="email"><?php _e(\'Email\', \'newtheme\') ?></label> <?php if ($req) _e(\'<span class="required">*</span>\', \'newtheme\') ?></div>
<div class="form-input"><input id="email" name="email" type="text" value="<?php echo $comment_author_email ?>" size="30" maxlength="50" tabindex="4" /></div>
</div><!-- #form-section-email .form-section -->
<div id="form-section-url" class="form-section">
<div class="form-label"><label for="url"><?php _e(\'Website\', \'newtheme\') ?></label></div>
<div class="form-input"><input id="url" name="url" type="text" value="<?php echo $comment_author_url ?>" size="30" maxlength="50" tabindex="5" /></div>
</div><!-- #form-section-url .form-section -->
<?php endif /* if ( $user_ID ) */ ?>
<div id="form-section-comment" class="form-section">
<div class="form-label"><label for="comment"><?php _e(\'Comment\', \'newtheme\') ?></label></div>
<div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6"></textarea></div>
</div><!-- #form-section-comment .form-section -->
<div id="form-allowed-tags" class="form-section">
<p><span><?php _e(\'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:\', \'newtheme\') ?></span> <code><?php echo allowed_tags(); ?></code></p>
</div>
<?php do_action(\'comment_form\', $aspirasi->ID); ?>
<div class="form-submit"><input id="submit" name="submit" type="submit" value="<?php _e(\'Post Comment\', \'newtheme\') ?>" tabindex="7" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></div>
</form><!-- #commentform -->
</div><!-- .formcontainer -->
</div><!-- #respond -->
<?php endif /* if ( \'open\' == $post->comment_status ) */ ?>
</div><!-- #comments -->
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
不要构建自己的表单,也不要修改comments.php
- 它的用途有点不同,我认为你不应该把它包含在侧边栏中。
只是放comment_form
侧栏模板中的函数调用。它需要2个参数:args
和post_id
.
所以你可以这样做:
$args = array(
... // your custom arguments (you can leave it empty
);
comment_form( $args, $post_id );
您应该将此代码放置在哪里?在侧边栏模板的某个地方。(sidebar.php或类似的东西,但这取决于您的主题)。