最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - How to jump to newly posted comment anchor after submit?

programmeradmin6浏览0评论

I have a standard comment form in my theme. When user fills in the form and submits it, the comment appears in the comments list. But page does not scroll to the newly posted comment. Each comment url has an anchor:

How to make the page scroll to the newly posted comment right after post submit?

EDIT:

My comment form:

$args = array(
'fields' => apply_filters(
    'comment_form_default_fields', array(
        'author' =>'Ismingiz'.'<span style="color:red;">*</span><br>'.'<input id="author" class="form-control" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"/><br>',
    'email'  => 'Email'.'<span style="color:red;">*</span><br>'.'<input id="email" class="form-control" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .'" size="30" /><br>' ,)
),
    'comment_field' => '' . '<div class="input-group commenting-input-group input-group-lg"><textarea id="comment" class="form-control" name="comment" placeholder="Fikringiz matni..." cols="45" rows="8" aria-required="true"></textarea><br>',

'comment_notes_before' => '',
'title_reply' => '',
'class_submit'      => 'btn send-comment-button',
'label_submit'      => __( 'Yuborish' ),
'comment_notes_after' => '',
'submit_field' => '<p class="form-submit">%1$s %2$s</a></div>',
'logged_in_as' => '',
);

    comment_form($args);
?>

Comments loop:

function format_comment() {  ?>
      <div class="col-xs-2 col-md-3">  
              <?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
            </div>
            <div class="col-xs-10 col-md-9 comment-content">
              <div class="commenter">
                <a href="<?php comment_link(); ?>"><?php comment_author(); ?></a>
                <div class="comment-date">
                  <?php comment_date(); ?>
                </div>
              </div>
              <div class="comment">
                <?php comment_text(); ?>
              </div>
            </div>

I have a standard comment form in my theme. When user fills in the form and submits it, the comment appears in the comments list. But page does not scroll to the newly posted comment. Each comment url has an anchor:

http://example/post-name/#comment-3

How to make the page scroll to the newly posted comment right after post submit?

EDIT:

My comment form:

$args = array(
'fields' => apply_filters(
    'comment_form_default_fields', array(
        'author' =>'Ismingiz'.'<span style="color:red;">*</span><br>'.'<input id="author" class="form-control" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"/><br>',
    'email'  => 'Email'.'<span style="color:red;">*</span><br>'.'<input id="email" class="form-control" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .'" size="30" /><br>' ,)
),
    'comment_field' => '' . '<div class="input-group commenting-input-group input-group-lg"><textarea id="comment" class="form-control" name="comment" placeholder="Fikringiz matni..." cols="45" rows="8" aria-required="true"></textarea><br>',

'comment_notes_before' => '',
'title_reply' => '',
'class_submit'      => 'btn send-comment-button',
'label_submit'      => __( 'Yuborish' ),
'comment_notes_after' => '',
'submit_field' => '<p class="form-submit">%1$s %2$s</a></div>',
'logged_in_as' => '',
);

    comment_form($args);
?>

Comments loop:

function format_comment() {  ?>
      <div class="col-xs-2 col-md-3">  
              <?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
            </div>
            <div class="col-xs-10 col-md-9 comment-content">
              <div class="commenter">
                <a href="<?php comment_link(); ?>"><?php comment_author(); ?></a>
                <div class="comment-date">
                  <?php comment_date(); ?>
                </div>
              </div>
              <div class="comment">
                <?php comment_text(); ?>
              </div>
            </div>

Share Improve this question edited Nov 7, 2016 at 9:44 Azamat asked Nov 7, 2016 at 6:45 AzamatAzamat 3611 gold badge4 silver badges15 bronze badges 4
  • Sounds like javascript to run on page load. Not really a WordPress issue. You just need a scroll lib like iamdustan/smoothscroll and an anchor. – jgraup Commented Nov 7, 2016 at 6:58
  • But how do I set up the submit form in order to scroll to the posted comment? – Azamat Commented Nov 7, 2016 at 7:19
  • seems like your comment lack an anchor. – Mark Kaplun Commented Nov 7, 2016 at 9:54
  • <a href="<?php comment_link(); ?>"> this is the anchor link! – Azamat Commented Nov 7, 2016 at 17:55
Add a comment  | 

1 Answer 1

Reset to default 0

It seems that the WordPress comment box isn't working properly. Or maybe you are using any comment plugin like CommentLuv then it's the Javascript problem. You can check the comment box code in the theme. The loop showing the answers should be perfect to fetch the URL of the author.

发布评论

评论列表(0)

  1. 暂无评论