在主题根目录下functions.php插入如下代码
// Define path and URL to the ACF plugin. define('MY_ACF_PATH', get_stylesheet_directory() . '/lib/acf/'); define('MY_ACF_URL', get_stylesheet_directory_uri() . '/lib/acf/'); // Include the ACF plugin. include_once(MY_ACF_PATH . 'acf.php'); // Customize the url setting to fix incorrect asset URLs. add_filter('acf/settings/url', 'my_acf_settings_url'); function my_acf_settings_url($url) { return MY_ACF_URL; } // (Optional) Hide the ACF admin menu item. add_filter('acf/settings/show_admin', 'my_acf_settings_show_admin'); function my_acf_settings_show_admin($show_admin) { return true; }
基本显示(阵列)
本示例演示如何在使用array
返回式。这种返回类型使我们能够很容易地访问数据,例如url
和filename
.
<?php $file = get_field('file');if( $file ): ?> <a href="<?php echo $file['url']; ?>"><?php echo $file['filename']; ?></a><?php endif; ?>
高级显示器(阵列)
这个例子演示了如何在使用array
返回式。这种返回类型使我们能够很容易地访问数据,例如url
,title
,type
更多。
<?php $file = get_field('file');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; ?>
基本显示(ID)
本示例演示如何在使用ID
返回式。
<?php $file = get_field('file');if( $file ): $url = wp_get_attachment_url( $file ); ?> <a href="<?php echo esc_html($url); ?>" >Download File</a><?php endif; ?>
基本显示(网址)
本示例演示如何在使用URL
返回式。
<?php if( get_field('file') ): ?> <a href="<?php the_field('file'); ?>" >Download File</a><?php endif; ?>
转载请注明:Wordpress» WordPress 下载功能【Advanced Custom Fields PRO自定义字段文件下载调用
标签: