Comment count not working
Viewing 2 replies - 1 through 2 (of 2 total)
-
I’ve discovered what the problem is, but I don’t know how to fix it. The code I’m using to pull the first image from each post causes the comment count to break. I don’t know what in it is doing that, or if there is an alternate to pull the first image.
Here is the code that is breaking things:<?php global $post; $default_size = 'medium'; $attachments = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'numberposts' => 1) ); if($attachments) : foreach($attachments as $id => $attachment) : $img = wp_get_attachment_image_src($id, $default_size); endforeach; else : $img=null; endif; ?>Figured out a solution, if anyone runs into this in the future. changed the method in which I get images to:
$images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'numberposts' => 1) ); foreach ( $images as $attachment_id => $attachment ) : $img = wp_get_attachment_image_src($attachment_id, 'medium'); endforeach;I don’t know why this is better, but it doesn’t screw up the comment count. Here is the whole thing:
<div id="content" class="narrowcolumn"> <?php $temp_query = $wp_query; ?> <?php query_posts('showposts=200&orderby=date&order=DESC&cat=-16'); ?> <ul id="ArticleList"> <?php while (have_posts()) : the_post(); ?> <li class="post" id="post-<?php the_ID(); ?>"> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'numberposts' => 1) ); foreach ( $images as $attachment_id => $attachment ) : $img = wp_get_attachment_image_src($attachment_id, 'medium'); endforeach; ?> <a href="<?php the_permalink() ?>"><img src="<?php echo ($img[0]);?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a> <small>By <a href="mailto:<?php the_author_email();?>"><?php the_author_firstname(); ?> <?php the_author_lastname(); ?></a></small> | <small>Date posted: <?php the_date(); ?></small><br /> <span class="NumComments"> <?php comments_popup_link('<span class="CommentWord">No Comments</a>', '<span class="CommentNumber">1</span> <span class="CommentWord">Comment</a>', '<span class="CommentNumber">%</span> <span class="CommentWord">Comments</a>'); ?> </span> <p><?php the_excerpt(); ?></p> </li> <?php endwhile; ?> </ul> </div>
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Comment count not working’ is closed to new replies.
(@aquagrrl)
16 years, 5 months ago
I can’t get comment counts to work. I tried comments_popup_link and comments_number but they always show no comments. This is on a page using query_posts. I saw the http://wordpress.org/support/topic/162559 is_page fix but it does not work. I thought it might be query_posts but I saw several examples using comments_popup_link so I assume that it should work. Here is my code in question: