Forums

index.php won't display comment form, identical code works in single.php (6 posts)

  1. NhytFahl
    Member
    Posted 1 year ago #

    I want the comments and comment submission form (or the "you must be logged in" message) to appear below each post on my index page.

    It's working fine on single.php, when displaying a single page, but what appears to me to be the exact same code doesn't work in index.php.

    single.php:

    <?php get_header();?>
    <?php get_sidebar();?>
    	<div id="main">
    		<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    			<div class="box">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				<div class="post-content">
    				<?php the_content("Continue Reading »"); ?>
    				<?php wp_link_pages(); ?>											
    
    				<!--
    					<?php trackback_rdf(); ?>
    				-->
    				</div>
    				<p class="bottom">
    					<span class="cat"><?php the_category(' &amp;');?></span>
    					<span class="user"><?php the_author(); ?></span>
    					<span class="date"><?php the_time('d M Y'); ?></span>
    					<span class="comments"><?php comments_number(__('No Comments'), __('1 Comment'), __('% Comments')); ?></span><?php edit_post_link('edit this'); ?>
    				</p>
    			</div>
    			<?php comments_template(); ?>
    			<?php endforeach; else: ?>
    			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    			<?php endif; ?>
    			<p align="center"><?php posts_nav_link() ?></p>
    	</div>
    	</div> <!-- close content -->
    <?php get_footer();?>

    index.php:

    <?php get_header();?>
    	<?php get_sidebar();?>
    	<div id="main">
    		<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    			<div class="box">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				<div class="post-content">
    				<?php the_content("Continue Reading »"); ?>
    				<?php wp_link_pages(); ?>											
    
    				<!--
    					<?php trackback_rdf(); ?>
    				-->
    				</div>
    				<p class="bottom">
    					<span class="cat"><?php the_category(' &amp;');?></span>
    					<span class="user"><?php the_author(); ?></span>
    					<span class="date"><?php the_time('d M Y'); ?></span>
    					<span class="comments"><?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments')); ?></span><?php edit_post_link('edit this'); ?>
    				</p>
    			</div>
    			<?php comments_template(); ?>
    			<?php endforeach; else: ?>
    			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    			<?php endif; ?>
    			<p align="center"><?php posts_nav_link() ?></p>
    	</div>
    </div> <!-- close content -->
    <?php get_footer();?>

    The only difference I can see between these two pages, is 'comments_number' in single and 'comments_popup_link' in index, and changing it to 'comments_number' in index.php has no effect.

    For the life of me, I can't figure out why I can't get the comments and reply form to show up on the index page. Am I overlooking a setting somewhere? I've been through all the admin pages and can't find an option that enables/disables comments on the index page.

    Help, please?

  2. HandySolo
    moderator
    Posted 1 year ago #

    I want the comments and comment submission form (or the "you must be logged in" message) to appear below each post on my index page.

    Alas... I don't believe that's possible.

  3. NhytFahl
    Member
    Posted 1 year ago #

    Why wouldn't it be possible?

    It seems to me that if the comments template is called inside the main loop, it *should* display the comments and reply form.

    Unless, of course, there's some code in the post/comment handling internals that inhibits that behaviour.

    In that case, it would fall in the realm of a feature request to have that behaviour added, perhaps with a toggle in the Admin section to turn it on and off.

  4. whooami
    Member
    Posted 1 year ago #

    you can do this .. you just need to edit a little sumthen-sumthen in wp-includes/comments-template.php

    Go to line 280 .. that function, comments_template, is what is responsible for what youre seeing.

    specifically this :

    if ( ! (is_single() || is_page() || $withcomments) )
    		return;

    edit is as you like -- removing the check for if you are on a page or on single post page (aka permalink)

    Or remove the check all together.

  5. HandySolo
    moderator
    Posted 1 year ago #

    ...and print that out 'cause you'll do that edit after every security upgrade. ;-)

  6. NhytFahl
    Member
    Posted 1 year ago #

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.