Community Forums › Forums › Archived Forums › Design Tips and Tricks › Best way to show Comments on home page?
Tagged: comments
- This topic has 8 replies, 4 voices, and was last updated 9 years, 7 months ago by lmirabile.
-
AuthorPosts
-
March 12, 2014 at 12:16 pm #94479March 12, 2014 at 2:20 pm #94507March 12, 2014 at 3:17 pm #94516lmirabileMember
Thanks -- I did see that post, but it's only about the comment form, not the actual comments.
What did start me in the right direction was Trisha's comment in this post http://www.wpbeginner.com/wp-themes/how-to-show-comments-on-the-homepage-of-your-wordpress-theme/.
Setting global $withcomments = 1 is key.
However, I also found I had to alter genesis_get_comments_template, which deliberately excludes comments on the home page. I removed the action and added back a customized version allowing the front page too, like so:
remove_action( 'genesis_after_entry', 'genesis_get_comments_template' ); add_action( 'genesis_after_entry', 'tt_get_comments_template' ); /** * Modified copy of genesis/lib/structure/comments.php genesis_get_comments_template() * Renders comments and comment form on front page, as well as singular post pages */ function tt_get_comments_template() { global $withcomments; $withcomments = 1; global $post; if ( ! post_type_supports( $post->post_type, 'comments' ) ) return; if ( is_singular() && ! in_array( $post->post_type, array( 'post', 'page' ) ) ) comments_template( '', true ); elseif ( ( is_singular( 'post' ) || is_front_page() ) && ( genesis_get_option( 'trackbacks_posts' ) || genesis_get_option( 'comments_posts' ) ) ) comments_template( '', true ); elseif ( is_singular( 'page' ) && ( genesis_get_option( 'trackbacks_pages' ) || genesis_get_option( 'comments_pages' ) ) ) comments_template( '', true ); }
May 30, 2014 at 12:37 am #107429teamaherlMemberHi Imirable,
when you say 'Setting global $withcomments = 1 is key.'
where did you changed that. Which file? Is this all part of your code?
I've removed action from the comments.php and added yours, but now I don't have comments on the post at all.
(I'm new at this. thanks)
July 11, 2014 at 8:57 am #113905lmirabileMemberSorry for the slow reply. But in case it's helpful to someone else:
The code you copied has the "key" code -- it's the
"global $withcomments;
$withcomments = 1;"
part.The code you copied should go into the functions.php file in your child theme's folder. You do not need to remove anything from comments.php to make it work (and doing so probably caused the problem you see).
September 29, 2014 at 9:26 am #126163handsunParticipantI added this entire code above to the bottom of the functions.php in education pro and did not get a comment form on the home page, is there a step I am missing, thanks so much. I read in another post that I need to add
add_action( ‘genesis_after_loop’, ‘genesis_comments’ ) to front-page.phpI am using the Genesis featured posts widget to display the post on the home page
September 29, 2014 at 2:49 pm #126195lmirabileMemberI haven't looked at the details of the education pro theme, but this code is for displaying any posted comments, plus a form to add a comment, after the main loop on the home page. It won't work on a post loop that's inside a widget, I'm afraid. You could probably alter the widget if you were determined to, but it might be easier to alter the home page template (aka front-page.php) to show the posts you want in the main loop rather than using the featured post widget. But, as I said, I don't know that particular theme...
September 29, 2014 at 4:30 pm #126200handsunParticipantThat was the problem, I was using Genesis extender, so I switched that off, and then changed settings in Genesis, Theme Settings to show full length article, added the code to functions.php and voila, thank you so much!!
September 29, 2014 at 5:46 pm #126203lmirabileMemberWonderful - glad to hear it worked!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.