Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can make the function fb_comment_count call a optional variable, here I will call it $id, which will contains the ID of the attachement (optional so it will not break the function in other areas of site). Then with that ID we can get the attachment page's URL with get_attachment_link, is in that page that we'll find the comments for attachment. The code should be something like:</p> <pre><code>&lt;?php // FB Comment Count (by Zack Austin) // Changes by Bruno Cantuaria (bruno@cantuaria.net.br) function fb_comment_count($link = 'link', $id = 0) { global $post; $url = 'https://graph.facebook.com/'; if ($id &gt; 0) $posturl = get_attachment_link($id); else $posturl = get_permalink($post-&gt;ID); $url .= $posturl; $filecontent = wp_remote_retrieve_body(wp_remote_get($url, array('sslverify'=&gt;false))); $json = json_decode($filecontent); $count = $json-&gt;comments; if ($count == 0 || !isset($count)) { $count = 0; } $comments = $count; if ($count == 1) { $comments .= ''; } elseif ($count == 0) { $comments = '0'; } elseif ($count &gt; 1) { $comments .= ''; } if ($link == 'nolink') { return $comments; } else { return '&lt;a href="'.$posturl.'#comments" title="Comments for '.$post-&gt;post_title.'"&gt;'.$comments.'&lt;/a&gt;'; } } // Custom Gallery add_filter( 'post_gallery', 'my_post_gallery', 10, 2 ); function my_post_gallery( $output, $attr) { global $post, $wp_locale; static $instance = 0; $instance++; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } extract(shortcode_atts(array( 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ID', 'id' =&gt; $post-&gt;ID, 'itemtag' =&gt; 'dl', 'icontag' =&gt; 'dt', 'captiontag' =&gt; 'dd', 'columns' =&gt; 3, 'size' =&gt; 'thumbnail', 'include' =&gt; '', 'exclude' =&gt; '' ), $attr)); $id = intval($id); if ( 'RAND' == $order ) $orderby = 'none'; if ( !empty($include) ) { $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array('include' =&gt; $include, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby) ); $attachments = array(); foreach ( $_attachments as $key =&gt; $val ) { $attachments[$val-&gt;ID] = $_attachments[$key]; } } elseif ( !empty($exclude) ) { $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); $attachments = get_children( array('post_parent' =&gt; $id, 'exclude' =&gt; $exclude, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby) ); } else { $attachments = get_children( array('post_parent' =&gt; $id, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'image', 'order' =&gt; $order, 'orderby' =&gt; $orderby) ); } if ( empty($attachments) ) return ''; if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id =&gt; $attachment ) $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; return $output; } $itemtag = tag_escape($itemtag); $captiontag = tag_escape($captiontag); $columns = intval($columns); $itemwidth = $columns &gt; 0 ? floor(100/$columns) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $output = apply_filters('gallery_style', " &lt;style type='text/css'&gt; #{$selector} { margin: auto; } #{$selector} .gallery-item { float: {$float}; margin-top: 10px; text-align: center; width: {$itemwidth}%; } #{$selector} img { border: 2px solid #cfcfcf; } #{$selector} .gallery-caption { margin-left: 0; } &lt;/style&gt; &lt;!-- see gallery_shortcode() in wp-includes/media.php --&gt; &lt;div id='$selector' class='gallery galleryid-{$id}'&gt;"); $i = 0; foreach ($attachments as $id =&gt; $attachment) { $link = isset($attr['link']) &amp;&amp; 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $output .= "&lt;{$itemtag} class='gallery-item'&gt;"; $output .= "&lt;span class='photos-comment-number-wrap'&gt;&lt;span class='comment-number'&gt;". fb_comment_count('link', $id) ."&lt;/span&gt;&lt;/span&gt;"; $output .= " &lt;{$icontag} class='gallery-icon'&gt; $link &lt;/{$icontag}&gt;"; $output .= "&lt;/{$itemtag}&gt;"; if ( $columns &gt; 0 &amp;&amp; ++$i % $columns == 0 ) $output .= '&lt;br style="clear: both" /&gt;'; } $output .= " &lt;br style='clear: both;' /&gt; &lt;/div&gt;\n"; return $output; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload