Last active
August 29, 2015 14:19
-
-
Save Ritesh-patel/f0dbb361e2f2023cd4c0 to your computer and use it in GitHub Desktop.
rtMedia comment counts in media gallery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to get comment count of one media | |
function custom_get_rtmedia_media_comment_count( $id = false ){ | |
if( $id === false ){ | |
$id = rtmedia_media_id(); | |
} | |
$commentcount = wp_count_comments( $id ); | |
if ( isset( $commentcount->total_comments ) ){ | |
$commentcount = intval( $commentcount->total_comments ); | |
} else { | |
$commentcount = 0; | |
} | |
return $commentcount; | |
} | |
// Use this function in gallery template | |
function custom_rtmedia_media_comment_count(){ | |
global $rtmedia_backbone; | |
if ( $rtmedia_backbone[ 'backbone' ] ){ | |
echo '<%= comment_count %>'; | |
} else { | |
echo custom_get_rtmedia_media_comment_count(); | |
} | |
} | |
// add "comment_count" in return backbone object | |
function rtmedia_backbone_template_add_comment_count( $media_array ){ | |
$media_array->comment_count = custom_get_rtmedia_media_comment_count( $media_array->media_id ); | |
return $media_array; | |
} | |
// filter return backbone object | |
add_filter( 'rtmedia_media_array_backbone', 'rtmedia_backbone_template_add_comment_count', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just call
custom_rtmedia_media_comment_count()
function in media-gallery-item.php template to show comment count in media gallery.