星期三 , 22 1 月 2025

如果用wp自带的file模块在文章上传文件如何获取到地址

if (have_posts()) :
    while (have_posts()) : the_post();
        // Get the post content
        $content = get_the_content();

        // Check if the post content contains the file block
        if (has_block('file', $content)) {
            // Get the file blocks from the post content
            $file_blocks = parse_blocks($content);

            // Loop through the file blocks
            foreach ($file_blocks as $block) {
                if ($block['blockName'] === 'core/file') {
                    // Get the file URL from the block attributes
                    $file_url = $block['attrs']['href'];
                    echo '<p>File URL: ' . $file_url . '</p>';
                }
            }
        }
    endwhile;
endif;