Here are two functions I'm working with (line 1 and line 33): http://pastebin.com/GWCJGS1i
If you notice around line 123, I have included the concatenated function . fb_comment_count() .
. For some reason, this produces an i开发者_开发问答ncorrect comment count. It just shows zero no matter how many comments there are.
However, if I insert <?php echo fb_comment_count(); ?>
into a page template, it works fine. Why does this happen? How can I get the correct comment count to show up with the concatenated function?
Here is the page template:
<?php get_header();?>
<section id="content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<section class="entry">
<?php echo fb_comment_count(); ?>
<p class="attachment"><?php echo wp_get_attachment_image( $post->ID, 'medium' ); ?></p>
<div class="caption">
<?php if ( !empty($post->post_excerpt) ) the_excerpt(); // this is the "caption" ?>
</div>
</section>
</article>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<p>Sorry, no attachments matched your criteria.</p>
<?php endif; ?>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Two possible causes:
- The global $post variable is not set when you call your function from functions.php but it is when inside the template.
- The call to get_posts() is trashing the $post global.
精彩评论