You're re-inventing the wheel here ;-)
You're bypassing WordPress with this approach, so that's explains the error message.
Accessing any custom file, within your theme directory, will not load WordPress core automatically.
This is already supported by the WordPress core.
You should check out
In general, you can get all your comments, for a given post with:
123 is some post ID.
You can override the default comment popup template, by placing your own version of the
comments-popup.php file, in the current theme directory.
The default one is located in
Note on WP 4.2.2 - Incorrect inline documentation
In core we got this description:
- The template path is filterable via the 'comments_popup_template' hook.
but it's not correct. The template comes from:
$template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
get_query_template() we have the following cleaning:
$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
where the type
comments_popup is changed to
The correct filter is therefore:
add_filter( 'commentspopup_template', function( $template )
It looks like the correct type was meant to be
comments-popup and not
comments_popup. But then we can wonder why the underscore is removed - check out ticket #21213 to read more on that.
I filed a core trac ticket here #32989, regarding the inline documentation.