Question

I would like the create a link that point to the comment part. So when reader click on my link, it will scroll down to the place that they can leave a reply.

I have read some tutorial which teach how to create tag #id for headings in a post. However, I don't know how to do this for the comment part.

Please help! Thank you so much!

Était-ce utile?

La solution

The code below should be something similar to what you're looking for

Inside the loop template you use for listing blogs (like index.php) you need something like this

<a href="<?php the_permalink(); ?>/#respond"> <!-- The blog permalink with the anchor ID after -->
    <i class="fa fa-comments-o"></i> Leave a Comment
</a>

Inside your comments.php file you could have this

<?php if ('open' == $post->comment_status) : ?>

    <div id="respond"> <!-- This is the element we are pointing to -->
        <!-- Code for comments... -->
    </div>

<?php endif; // if you delete this the sky will fall on your head ?>

Autres conseils

I found a simpler solution, based on CoderSte's. Delete the

<?php the_permalink(); ?>/

from the first block of code, and then put it where you desire. That's it. The comment form already has the "respond" id, so you won't need to add the second block of code.

Removing the permalink part will prevent the site from reloading. It will simply jump to the comment section, which is the desired behavior.

This is all I added to my site. Add your button image in the tag.

<a href="#respond"><img src="" alt="" width="100" height="100" /></a>

If you are inside the loop you can also use the comments_link() function to echo the link or get_comments_link() to return.

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top