• Hello wordpress folk!

    I’ve been coming back up to speed with WordPress after several years. I’m technically savvy, at least enough to reverse engineer code, but this one has me stumped. So far everything is working the way I want, except that each post now has every comment from the database attached to it. I can get the correct number of comments to display after each post however, so I know the database isn’t corrupted. I’m likely missing a variable of some kind and I’ve tried everything including several suggestions from the support pages related to what I’m experiencing.

    I am not using a template. I am using all this code embedded in the index.php file located in the root of a standard WP install folder which I have called “blog”, since that is the only page that will contain anything blog related. My intention is to use blog functionality within a static HTML design.

    Here’s the code. It’s been greatly simplified to only show WP related items.

    Thank you in advance!!

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Blog</title>
    <?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('wp-blog-header.php');
    query_posts( 'posts_per_page=5' );?>
    </head>
    <body>
    <div class="blog">
    	<?php while (have_posts() ): the_post(); ?>
            <h2><?php the_title(); ?></h2>
            <p><i>Posted: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?></i></p>
    		<?php the_content(); ?>
    		<?php edit_post_link('Edit','?|?'); ?>
    		<?php
    		printf( _nx( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'comments title' ),
    		number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
    		?>        
    
            <!---COMMENT LIST GOES BELOW--->
    
    		<h5>
    		<ol class="commentlist">
    		<?php
    		//Gather comments for a specific page/post
    		$comments = get_comments(array(
    			'post_id' => 0,
    			'status' => 'approve' //Change this to the type of comments to be displayed
    		));
    
    		//Display the list of comments
    		wp_list_comments(array(
    			'per_page' => 10, //Allow comment pagination
    			'reverse_top_level' => false //Show the latest comments at the top of the list
    		), $comments);
    		?>
    
            </h5>
    
        	<!---COMMENT LIST GOES ABOVE--->
    
            <?php comment_form(); ?>
    	<?php endwhile; ?>
            </div>
    </body>
    </html>
Viewing 1 replies (of 1 total)
  • I think this should do it:

    <ol class="commentlist">
    		<?php
    		//Gather comments for a specific page/post
                    $id = get_the_ID();
    		$comments = get_comments(array(
    			'post_id' => $id,
    			'status' => 'approve' //Change this to the type of comments to be displayed
    		));
    
    		//Display the list of comments
    		wp_list_comments(array(
    			'per_page' => 10, //Allow comment pagination
    			'reverse_top_level' => false //Show the latest comments at the top of the list
    		), $comments);
    		?>
Viewing 1 replies (of 1 total)
  • The topic ‘Same comments on every post, stumped!’ is closed to new replies.