- 2016-05-30 at 17:27 #7797
Not sure if this is possible already, I can’t see a template tag for this.
What I’m currently trying to do is display the number of comments a file has while browsing a list of files, like this:
<?php echo wp_count_comments(%file_post_id%)->approved; ?>
However this obviously doesn’t work since %file_post_id% means nothing to the wp_count_comments function.
What would I need to replace this with, or maybe could a template tag be added for this functionality?
2016-06-06 at 14:45 #7806FabianParticipant
- This topic was modified 5 years, 11 months ago by Sean Byrnes.
<?php echo wp_count_comments($f->file_post_id)->approved; ?>2016-06-09 at 22:39 #7839
That looked good, but for some reason $f->file_post_id keeps returning 0.
I’m using this code in the “Templates and Scripts” tab, editing the Default File Template in case you needed to know that.
Any other ideas? Thanks though!2016-06-09 at 22:44 #7840
Also $f->post_id is just blank, thought I’d give that a try.2016-06-10 at 11:53 #7854FabianParticipant
<?php echo wp_count_comments($f->file_wpattach_id)->approved; ?>
file_wpattach_idis the correct ID of the file page, whereas
file_post_idis the ID of the post the file is attached to.2016-06-11 at 01:14 #7883
Yep, that worked great, thanks a lot!
- You must be logged in to reply to this topic.