欢迎来到路由器窝!

WordPress 下载功能【Advanced Custom Fields PRO自定义字段文件下载调用

浏览次数:

作者: 小编

信息来源:

更新日期: 2024-03-07 17:31

文章简介

基本显示(阵列)本示例演示如何在使用array 返回式。这种返回类型使我们能够很容易地访问数据,例如url 和filename .<?php$file = get_field(‘file‘);if( $file ): ?> <a

  • 正文开始
  • 相关文章

https://www.advancedcustomfields.com/resources/全部参数

https://www.advancedcustomfields.com/resources/file/文件参数

在主题根目录下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自定义字段文件下载调用

标签:
上一页:wordpress调用指定分类置顶文章
下一页:WordPress True / False功能参数
最近更新作品
acf判断
更新时间:2024-04-17

891人已经看过了!

指定栏目ID另类调用配合acf
更新时间:2024-04-16

857人已经看过了!

word press 自定义文章类型制作留言功能
更新时间:2024-03-10

985人已经看过了!

php if  ifelse 循环
更新时间:2024-03-09

575人已经看过了!

栏目模板选择插件栏目模板
更新时间:2024-03-08

738人已经看过了!

contact-form-7历史版本WP SMTP配合使用
更新时间:2024-03-08

809人已经看过了!

WordPress True / False功能参数
更新时间:2024-03-08

928人已经看过了!

wordpress调用指定分类置顶文章
更新时间:2024-03-07

519人已经看过了!

WordPress父分类调用子分类名称和文章列表
更新时间:2024-03-07

519人已经看过了!