WP-Filebase Pro › Forums › General Support › Get comment count for File Pages
- This topic has 5 replies, 2 voices, and was last updated 8 years, 4 months ago by Sean Byrnes.
- AuthorPosts
- 2016-05-30 at 17:27 #7797Sean ByrnesParticipant
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?
- This topic was modified 8 years, 4 months ago by Sean Byrnes.
2016-06-06 at 14:45 #7806FabianParticipantHi, try
<?php echo wp_count_comments($f->file_post_id)->approved; ?>
2016-06-09 at 22:39 #7839Sean ByrnesParticipantThat 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 #7840Sean ByrnesParticipantAlso $f->post_id is just blank, thought I’d give that a try.
2016-06-10 at 11:53 #7854FabianParticipantSorry, try
<?php echo wp_count_comments($f->file_wpattach_id)->approved; ?>
file_wpattach_id
is the correct ID of the file page, whereasfile_post_id
is the ID of the post the file is attached to.2016-06-11 at 01:14 #7883Sean ByrnesParticipantYep, that worked great, thanks a lot!
- AuthorPosts
- You must be logged in to reply to this topic.