douxi8119 2019-03-30 13:21
浏览 43

在WordPress库中获取总图像的“计数”

I m making a theme and want to add total image counts of a gallery in a single post. I did auto number images and want to show 1 of 4, 2 of 4 ... before each image.

function gallery_callback( $matches )
{

    $media = get_attached_media( 'image',  $post_id);
    $count2 = count($media);

    static $count = 0;
    $count += 1;

return "<span class='gallery-number'> $count $count2</span>" . $matches[0];

} 

This code show number before each image. And $count2 counts all images in post. But i want to count only gallery images. It shows all images attached to post ( thumbnail, related posts, widget images etc... )

How can i retrieve gallery image count of a post outside the loop.

https://resmim.net/f/131WmH.jpg

In the image first number shows auto number of images ( thats correct ) - Second number shows all images in post ( includes everything - actually there is 4 images in the gallery )

Thanks for help.

  • 写回答

1条回答 默认 最新

  • doubairan4213 2019-03-30 13:24
    关注

    Because This code show number before each image. And $count2 counts all images in post. But i want to count only gallery images. It shows all images attached to post ( thumbnail, related posts, widget images etc... )

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题