• This topic has 1 reply, 2 voices, and was last updated 1 year ago by vako.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #75593
    Pär Iwarson
    Participant
    Premium Member

    I would like to let users comment on the blog posts in the feed on the start page without having to go to the posts page to comment. So I have copied the template file blog-grid.php to my child theme and added comments_template(); to it. But it doesn’t render anything. It is just empty. Is it impossible to render the comments section on the start page? Or how can I achieve it?

     

    #75594
    vako
    Keymaster
    Premium Member

    Hi Par,

    Thank you for reaching out with your question about enabling comments on the blog posts in the feed on the start page.

    It’s great to hear that you’re using a child theme and attempting to modify the blog-grid.php template. However, WordPress does not natively support rendering the comments template directly on the start page feed. Here are a few steps and solutions to help you achieve this functionality:

    1. Ensure Comments Are Enabled:

    First, make sure that comments are enabled for your blog posts. You can do this by navigating to the WordPress Dashboard > Settings > Discussion and ensuring that “Allow people to post comments on new articles” is checked.

    2. Modify the Template Correctly:

    Adding comments_template(); alone might not be enough due to how WordPress handles comment rendering. You need to ensure that the comments template is called within the loop and that the necessary comment query is set up.

    3. Custom Solution:

    Since rendering comments on the start page feed is not a standard feature, you might need a custom solution. Here’s a basic example of how you can modify your blog-grid.php to include comments:

    php

    <?php

    // Check if there are posts

    if (have_posts()) :

    while (have_posts()) : the_post();

    // Your code to display the post content

     

    // Display comments

    if (comments_open() || get_comments_number()) :

    // Load the comment template

    comments_template();

    endif;

    endwhile;

    endif;

    ?>

    ### 4. AJAX-Based Solution:

    Another approach is to use AJAX to load comments dynamically without refreshing the page. This would involve writing custom JavaScript to fetch and display comments when a user clicks a “Show Comments” button.

    5. Plugin Solution:

    If custom coding is not preferable, consider using a third-party plugin. While there may not be a plugin that directly adds comment sections to your start page feed, you might find plugins that offer more flexible comment display options that could be customized to fit your needs.

    Troubleshooting Tips:

    Clear Cache: Ensure that you clear any caching mechanisms on your site to see changes.

    Debugging: Use var_dump() or print_r() to debug and ensure your code is being executed as expected.

    If after following these steps you still encounter issues, it might require a more in-depth look at your theme’s structure and how it handles the blog grid and comments.

    Please let us know if you need further assistance or if you would like more detailed instructions on implementing any of these solutions.

    Best regards

     

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.