WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show comments on home page? (11 posts)

  1. lucid_design
    Member
    Posted 5 years ago #

    I want to show all comments for each post on the home page. I'm using the minimalism theme.

    None of these work for this theme:

    http://wordpress.org/support/topic/244860?replies=8

    http://wordpress.org/support/topic/246023?replies=3

  2. stvwlf
    Member
    Posted 5 years ago #

    Comments display nicely in the single.php template file.

    Open your theme's single.php in an editor and copy the code that displays the comments. It should be pretty obvious since it will say comments in the code.

    Then open your homepage template file and paste the same code into it.

    Make sure you paste the code inside the WP loop as you need it to execute once for each post on the homepage. And also be sure to make a backup copy of the file before you change anything.

  3. Shane G
    Member
    Posted 5 years ago #

    Hi,

    You need to edit index.php file of your theme...

    find this code:

    <?php // Load Comments template (on single post pages, and "Page" pages, if set on options page)
            if ( is_single() OR ( is_page() && $bfa_ata_comments_on_pages == "Yes") ) {
                if (function_exists('paged_comments')) {
                    paged_comments_template(); // If plugin "Paged Comments" is activated, for WP 2.6 and older
                    } else {
                    comments_template(); // This will load either legacy comments template (for WP 2.6 and older) or the new standard comments template (for WP 2.7 and newer)
                }
            } ?>

    Replace:

    `<?php // Load Comments template (on single post pages, and "Page" pages, if set on options page)
    if ( is_single() OR ( is_page() && $bfa_ata_comments_on_pages == "Yes" && !is_front_page() )) {
    if (function_exists('paged_comments')) {
    paged_comments_template(); // If plugin "Paged Comments" is activated, for WP 2.6 and older
    } else {
    comments_template(); // This will load either legacy comments template (for WP 2.6 and older) or the new standard comments template (for WP 2.7 and newer)
    }
    } ?>`

    Thanks,

    Shane G.

  4. lucid_design
    Member
    Posted 5 years ago #

    Thanks, but I'm having trouble.

    stvwlf: I don't seem to be finding the right code from the single.php. would you help me locate that? The file is here:

    '<?php get_header(); ?>

    <div id="content" class="narrowcolumn">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="navigation">
    <div class="alignleft"><?php previous_post_link('« %link') ?></div>
    <div class="alignright"><?php next_post_link('%link »') ?></div>
    </div>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>

    <div class="entry">
    <?php the_content('<p class="serif">' . __('Read the rest of this entry »', 'minimalism') . '</p>'); ?>

    <?php wp_link_pages(array('before' => '<p>' . __('Pages:', 'minimalism') . ' ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    <?php the_tags( '<p>' . __('Tags:', 'minimalism') . ' ', ', ', '</p>'); ?>

    <p class="postmetadata alt">
    <small>
    <?php /* This is commented, because it requires a little adjusting sometimes.
    You'll need to download this plugin, and follow the instructions:
    http://binarybonsai.com/archives/2004/08/17/time-since-plugin/ */
    /* $entry_datetime = abs(strtotime($post->post_date) - (60*120)); $time_since = sprintf(__('%s ago', 'minimalism'), time_since($entry_datetime)); */ ?>
    <?php printf(__('This entry was posted %1$s on %2$s at %3$s and is filed under %4$s.', 'minimalism'), $time_since, get_the_time(__('l, F jS, Y', 'minimalism')), get_the_time(), get_the_category_list(', ')); ?>
    <?php printf(__("You can follow any responses to this entry through the RSS 2.0 feed.", "kubrick"), get_post_comments_feed_link()); ?>

    <?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    // Both Comments and Pings are open ?>
    <?php printf(__('You can leave a response, or trackback from your own site.', 'minimalism'), trackback_url(false)); ?>

    <?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
    // Only Pings are Open ?>
    <?php printf(__('Responses are currently closed, but you can trackback from your own site.', 'minimalism'), trackback_url(false)); ?>

    <?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    // Comments are open, Pings are not ?>
    <?php _e('You can skip to the end and leave a response. Pinging is currently not allowed.', 'minimalism'); ?>

    <?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
    // Neither Comments, nor Pings are open ?>
    <?php _e('Both comments and pings are currently closed.', 'minimalism'); ?>

    <?php } edit_post_link(__('Edit this entry', 'minimalism'),'','.'); ?>

    </small>
    </p>

    </div>
    </div>

    <?php comments_template(); ?>

    <?php endwhile; else: ?>

    <p><?php _e('Sorry, no posts matched your criteria.', 'minimalism'); ?></p>

    <?php endif; ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>'

    And the index.php file is:

    '<?php get_header(); ?>

    <div id="content" class="narrowcolumn">

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'minimalism'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></h2>
    <small><?php the_time(__('F jS, Y', 'minimalism')) ?> <!-- by <?php the_author() ?> --></small>

    <div class="entry">
    <?php the_content(__('Read the rest of this entry »', 'minimalism')); ?>
    </div>

    <p class="postmetadata"><?php the_tags(__('Tags:', 'minimalism') . ' ', ', ', '
    '); ?> <?php printf(__('Posted in %s', 'minimalism'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit', 'minimalism'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »', 'minimalism'), __('1 Comment »', 'minimalism'), __('% Comments »', 'minimalism'), '', __('Comments Closed', 'minimalism') ); ?></p>
    </div>

    <?php endwhile; ?>

    <div class="navigation">
    <div class="alignleft"><?php next_posts_link(__('« Older Entries', 'minimalism')) ?></div>
    <div class="alignright"><?php previous_posts_link(__('Newer Entries »', 'minimalism')) ?></div>
    </div>

    <?php else : ?>

    <h2 class="center"><?php _e('Not Found', 'minimalism'); ?></h2>
    <p class="center"><?php _e('Sorry, but you are looking for something that isn’t here.', 'minimalism'); ?></p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>

    <?php endif; ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>'

    Sorry, I don't know what 'inside the WP loop' means.

    Thanks for your help.

  5. stvwlf
    Member
    Posted 5 years ago #

    This one line
    <?php comments_template(); ?>
    calls in the comments display

    I would place it, in index.php, just before this line
    <?php endwhile; ?>

    If you find its not displaying where you want it, you can then move the one line around until you find the location that you prefer.

  6. lucid_design
    Member
    Posted 5 years ago #

    Thanks for your reply. I placed that line of code where you suggested it, with no success. Then I moved it around. Still no display of comments. Will it help to look at the code of this page?

    http://luisakolker.com/blog/

  7. stvwlf
    Member
    Posted 5 years ago #

    Before I said put <?php comments_template(); ?> just before
    <?php endwhile; ?>

    Try putting it before

    </div>
    <?php endwhile; ?>

    Also, at the top of index.php add this line
    <!-- index.php -->
    just after
    <?php get_header(); ?>

    If you still don't see comments, do a View / Source from your browser menu. Within the source code you should see the line
    <!-- index.php -->
    before the display of the post title. If you don't see that, it means WordPress is using a different template than index.php to display your homepage. Let me know if that happens.

  8. lucid_design
    Member
    Posted 5 years ago #

    I made the suggestions you gave. Comments are still not showing.

    The line

    <!-- index.php -->

    is appearing in the source code.

  9. stvwlf
    Member
    Posted 5 years ago #

    Hi

    I just tested this out, and learned something new.

    The comments code you are adding - use

    <?php
      $withcomments = "1";
      comments_template();
    ?>

    It goes before this:

    </div>
    <?php endwhile; ?>

    I've now seen this working on my system using the minimalism theme.

  10. lucid_design
    Member
    Posted 5 years ago #

    That's it! It works.

    Thank you stvwlf. I really appreciate your attention on this.

  11. elody
    Member
    Posted 5 years ago #

    I found the same piece of code to make comments appear on homepage (index.php), I thought it was all perfect, but when I started testing the Comments Navigation I found that the classes "alignleft" and "alignright" in "navigation" are just EMPTY, and nothing display !
    When I click the title of a post I go the its own page (single.php) where the links appear and everything works well.

    I think the problem comes from the function next_posts_link() and previous_posts_link(), that are supposed to work only in single.php, but I can't figure out how to fix it ...

    Pls help me, maybe I'm just missing something simple ?!

Topic Closed

This topic has been closed to new replies.

About this Topic