首页 文章

计数总图像附加到 Headers - wordpress的发布和打印结果

提问于
浏览
-2

我想在帖子 Headers 中显示图像总数 . 对于前:“我的帖子是这辆车出售(4张图片)”如果这是 Headers 我想在图像前打印4我的 Headers . 我尝试这个代码,但它显示0.我不知道为什么 . 所以,请你帮助我 . 请注意:我是php和wordpress的新手 .

$count = count( $attachments );
$specific = array();
$i = 1;

foreach ( $attachments as $attachment ) {
    $specific[$attachment->ID] = $i;
    ++$i;
}

1 回答

  • 0

    请尝试以下解决方案

    为此,您需要传递您的帖子ID

    <?php
    $getAttachments = get_children( array( 'post_parent' => $post->ID ) );
    $count = count( $getAttachments );
    echo $count;
    ?>
    

相关问题