Get WordPress comments outside of WordPress
Update: Apparently this code is also necessary when you want to list the comments on the blog page, and probably on archive pages as well. There could be a better solution, if you really care check out the P2 theme (and leave a comment).
Sometimes you want to access WordPress content outside of WordPress. There are various pages that explain how to this and it's really easy to do as well. What I tried to do was a little different though, I wanted to print comments outside of WordPress.
To my surprise wp_list_comments()
didn't output anything inside my custom loop. It turned out that $wp_query->comments
was NULL
, which I think is rather odd. I would have expected it to be defined like in a normal loop inside WordPress. However, the fix is trivial:
<?php global $post, $wp_query; $args = array( 'ID' => $post->ID, 'status' => 'approve', 'order' => 'ASC' ); $wp_query->comments = get_comments( $args ); wp_list_comments( ); comment_form(); }?>
comment_form()
is a WordPress 3.0 feature by the way, so you may not want to use it yet.
i got all the post of the all post not fro particular post and did not saw any comment post form there. I have a custom page outside of wordpress instal directory and this is the post details page. Thank you