使用 ACF Extended 显示多个文件

问题描述 投票:0回答:1

我在使用 ACF File 字段类型并在 Advanced Custom Fields Extended PRO 上启用“允许多个文件”时在 WordPress Post 上显示多个文件(.pdf、.docx、.xlsx 等)时遇到问题。

这是不起作用的代码:

    <?php
$file = get_field('documents');
if( $file ):

    // Extract variables.
    $url = $file['url'];
    $title = $file['title'];
    $caption = $file['caption'];
    $icon = $file['icon'];

    // Display image thumbnail when possible.
    if( $file['type'] == 'image' ) {
        $icon =  $file['sizes']['thumbnail'];
    }

    // Begin caption wrap.
    if( $caption ): ?>
        <div class="wp-caption">
    <?php endif; ?>

    <a href="<?php echo esc_attr($url); ?>" title="<?php echo esc_attr($title); ?>">
        <img src="<?php echo esc_attr($icon); ?>" />
        <span><?php echo esc_html($title); ?></span>
    </a>

    <?php 
    // End caption wrap.
    if( $caption ): ?>
        <p class="wp-caption-text"><?php echo esc_html($caption); ?></p>
        </div>
    <?php endif; ?>
<?php endif; ?>

任何人都可以帮助我如何在特定帖子上显示附件?

php wordpress advanced-custom-fields
1个回答
0
投票

这可能是您正在寻找的: https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/

示例页面上的代码对我来说几乎一字不差。

<?php if( have_rows('repeater_field_name', 'option') ): ?>

<ul>

<?php while( have_rows('repeater_field_name', 'option') ) : the_row(); ?>

    <li><?php the_sub_field('title'); ?></li>

<?php endwhile; ?>

</ul>

除了我自己使用它外,我与该文章没有任何关系。

© www.soinside.com 2019 - 2024. All rights reserved.