Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在wordpress中获取特定帖子的附加媒体总数?_Wordpress_Media_Posts - Fatal编程技术网

在wordpress中获取特定帖子的附加媒体总数?

在wordpress中获取特定帖子的附加媒体总数?,wordpress,media,posts,Wordpress,Media,Posts,我想在滑块中显示所有连接到特定文章的媒体,因此我想显示连接到特定文章的媒体总数。示例我想显示为1/5 2/5,依此类推。每个职位? 那么如何获得总计数呢? 以及根据增加计数器。您可以使用该功能。该函数返回一个数组,该数组包含给定帖子的所有连接媒体,数组长度为总计数 你能添加到目前为止你已经尝试过的代码吗?下面的代码就可以了 sizeof(get_attached_media( 'image', $post_id ) ) 检查下面的链接 我得到了我的答案: $attachments = ge

我想在滑块中显示所有连接到特定文章的媒体,因此我想显示连接到特定文章的媒体总数。示例我想显示为1/5 2/5,依此类推。每个职位? 那么如何获得总计数呢? 以及根据增加计数器。

您可以使用该功能。该函数返回一个数组,该数组包含给定帖子的所有连接媒体,数组长度为总计数


你能添加到目前为止你已经尝试过的代码吗?

下面的代码就可以了

  sizeof(get_attached_media( 'image', $post_id ) )
检查下面的链接

我得到了我的答案:

$attachments = get_children( array( 'post_parent' => $post->ID ) );
$count = count( $attachments );