Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Tiago Sa on "Function to retrieve comment panel"

$
0
0

Hi. I have a PHP function that retrieves the comment panel of a post. I retrieve the result by javascript and load it dynamically in the post. But, although everything else works fine, it doesn't detect that there are comments. Effectively the have_comments() returns false. However, if I force it to true, get_comment_pages_count() returns 0, get_option( 'page_comments' ) and basically comment listing doesn't work. Why is that?

include ( '../../../../wp-load.php' );
$t = 0;
if ( isset ( $_GET [ 'dwid' ] ) && intval ( $_GET [ 'dwid' ] ) > 0 ) $t = $_GET [ 'dwid' ];
$query = new WP_Query ( 'posts_per_page=1&include=' . intval ( $_GET [ 'dwid' ] ) );
if ( $query -> have_posts() ) {
	while ( $query -> have_posts() ) {
		$query -> the_post();
		if ( !post_password_required() ) { ?>
			<div id="comments"><?php comments_template();
				if ( have_comments() ) { ?>
					<h2 id="comments-title"><?php printf( _n( 'One thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'wpportgall' ), number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' ); ?></h2>
					<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
					<nav id="comment-nav-above">
						<h1 class="assistive-text"><?php _e( 'Comment navigation', 'wpportgall' ); ?></h1>
						<div class="nav-previous"><?php previous_comments_link( __( '&laquo; Older Comments', 'wpportgall' ) ); ?></div>
						<div class="nav-next"><?php next_comments_link( __( 'Newer Comments &raquo;', 'wpportgall' ) ); ?></div>
					</nav>
					<?php endif; ?>
					<ol class="commentlist">
						<?php wp_list_comments( array( 'callback' => 'wpportgall_comment' ) ); ?>
					</ol>
					<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
					<nav id="comment-nav-below">
						<h1 class="assistive-text"><?php _e( 'Comment navigation', 'wpportgall' ); ?></h1>
						<div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'wpportgall' ) ); ?></div>
						<div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'wpportgall' ) ); ?></div>
					</nav>
					<?php endif;
				} elseif ( !comments_open() ) { ?>
					<p class="nocomments"><?php echo dwTranslate ( 'Os comentários estão fechados.', 'Comments are closed.' ); ?></p>
				<?php } ?>
				<?php if ( comments_open() ) comment_form(); ?>
			</div><!-- #comments -->
		<?php } else echo dwTranslate ( 'Os comentários estão fechados.', 'Comments are closed.' );
	}
} else echo dwTranslate ( 'Os comentários estão fechados.', 'Comments are closed.' );

Viewing all articles
Browse latest Browse all 8245

Trending Articles