Comments on WordPress and Genesis
Troubleshooting a theme and placing comments where they normally weren’t. Theme creates a page with a list of posts and the first post is shown in it’s entirety. All post, category, and archive pages have the same structure. So the initial wp_query could be a page, an archive, a post, etc. The is_single()
function gave the most trouble as most of the comment functions continue to check if we are on a single page. If it’s not, it returns immediately, not printing out the comments.
The files in question are
wp-includes/comment-template.php
genesis/structure/comments.php
genesis/comments.php
wp-includes/comment-template.php
A wordpress file that fills out a comments_args variable and uses that to run a comment query. This query gets appended to the global $wp_query
variable. Then it runs the genesis/comments.php
file (unless the child theme has a comments.php
file in it).
genesis/comments.php
The parent theme file that checks if a password is required, adds the accessiblity heading, and then runs a list of do_action
‘s
/genesis/structure/comments.php
Contains all the add_action
‘s and the corresponding functions that are hooked in the actions. This is run when Genesis is initialized so all the hooks are in place.
Solution
Ended up having to change the $wp_query
global variable so that is_single()
would return true even though the initial query or subsequent was not for a single post.
Before the loop I removed the default comment hook:
remove_action( 'genesis_after_entry', 'genesis_get_comments_template' );
and added my own where I wanted the comments to appear. In this case, I wanted it in the <article>
tag:
add_action( 'genesis_entry_footer', 'gs_get_comments_template' );
function gs_get_comments_template() {
global $wp_query;
$is_single = is_single();
$wp_query->is_single = true;
comments_template('', true); // in wp_includes/comment-template.php
$wp_query->is_single = $is_single;
}