[wordpress插件] Advanced Custom Fields: Snippets高级自定义字段:摘要

wordpress 插件 文章 2020-01-27 12:20 616 0 全屏看文

AI助手支持GPT4.0

评分

0

0

描述

Adds useful functions for rendering image fields, link fields, repeater fields and flexible content for the Advanced Custom Fields plugin.

为“高级自定义字段”插件添加了用于渲染图像字段,链接字段,转发器字段和灵活内容的有用功能。

For detailed info look on Bitbucket.

有关详细信息,请查看Bitbucket

Main advantages

主要优势

    • write less code (do not repet same blocks of the code when writing down ACF custom fields)
    • 编写更少的代码(写下ACF自定义字段时,请勿重复代码的相同块)

    • built-in filters
    • 内置过滤器

    • works also for Gutenberg ACF Blocks
    • 也适用于古腾堡ACF区块

    • no init hooks etc (no impact on performance)
    • 没有初始化钩子(对性能没有影响)

    Usage

    用法

    Link

    链接

    Returns the snippet of a specific link field.

    返回特定链接字段的摘要。

      <?php    

    acf_snippet_get_link($selector, [$postId], [$args]);

    acf_snippet_get_link($ selector,[$ postId],[$ args]);

    ?>

    ?>

    Displays the snippet of a specific link field.

    显示特定链接字段的代码段。

      <?php    

    acf_snippet_the_link($selector, [$postId], [$args]);

    acf_snippet_the_link($ selector,[$ postId],[$ args]);

    ?>

    ?>

    Parameters
        

    参数
        

    $selector (string) (Required) ACF field name or ACF field key.

    $ selector (字符串)(必需) ACF字段名称或ACF字段键。

    Based on ACF get_field function.
        

    基于 ACF get_field函数
        

    $postId (integer|bool) (Optional) The post ID where the value is saved.

    $ postId (integer | bool)(可选)保存值的帖子ID。

    Use true for getting sub field.

    使用 true 获取子字段。

    Default value: false (current post).
        

    默认值: false (当前发布)。
        

    $args (array) (Optional) Array of link output arguments.

    $ args (array)(可选)链接输出参数的数组。

    Default value: null.

    默认值: null

    ‘class’ (string) class attribute of the anchor.

    锚的“类” (字符串) class 属性。

    ‘id’ (string) id attribute of the anchor.

    锚的'id' (字符串) id 属性。

    ‘title’ (string) title attribute text of the anchor.

    锚的“标题” (字符串) title 属性文本。

    Image

    图片

    Returns the snippet of a specific image field.

    返回特定图像字段的摘要。

      <?php    

    acf_snippet_get_image($selector, [$postId], [$args]);

    acf_snippet_get_image($ selector,[$ postId],[$ args]);

    ?>

    ?>

    Displays the snippet of a specific image field.

    显示特定图像字段的代码段。

      <?php    

    acf_snippet_the_image($selector, [$postId], [$args]);

    acf_snippet_the_image($ selector,[$ postId],[$ args]);

    ?>

    ?>

    Parameters
        

    参数
        

    $selector (string) (Required) ACF field name or ACF field key.

    $ selector (字符串)(必需) ACF字段名称或ACF字段键。

    Based on ACF get_field function.
        

    基于 ACF get_field函数
        

    $postId (integer|bool) (Optional) The post ID where the value is saved.

    $ postId (integer | bool)(可选)保存值的帖子ID。

    Use true for getting sub field.

    使用 true 获取子字段。

    Default value: false (current post).
        

    默认值: false (当前发布)。
        

    $args (array) (Optional) Array of image output arguments.

    $ args (array)(可选)图像输出参数的数组。

    Default value: null.

    默认值: null

    ‘size’ (string) Image size to use.

    “尺寸” (字符串)要使用的图像尺寸。

    Accepts any valid image size.

    接受任何有效的图像尺寸。

    Default value is full.

    默认值为 full

    ‘alt’ (string) alt attribute of the image.

    图像的'alt' (字符串) alt 属性。

    ‘id’ (string) id attribute of the image.

    图片的'id' (字符串) id 属性。

    ‘class’ (string) class attribute of the image.

    图像的“类” (字符串) class 属性。

    ‘title’ (string) title attribute of the image.

    图像的“标题” (字符串) title 属性。

    ‘srcset’ (bool) Use true for retrieving image’s srcset attribute.

    “ srcset” (布尔)使用 true 检索图像的 srcset 属性。

    Default value: false.

    默认值: false

    ‘loading’ (string) loading attribute of the image.

    图像的“加载” (字符串) 加载属性。

    Default value: lazy.

    默认值: lazy

    ‘link’ (bool|array) Array of attributes for anchor wrapped around the image.

    “链接” (布尔|数组)锚定在图片周围的属性数组。

    Default value: false.

    默认值: false

    ‘href’ (string) href attribute of the link.

    链接的'href' (字符串) href 属性。

    ‘target’ (string) target attribute of the link.

    链接的“目标” (字符串) target 属性。

    ‘class’ (string) class attribute of the link.

    链接的“类” (字符串) class 属性。

    ‘id’ (string) id attribute of the link.

    链接的'id' (字符串) id 属性。

    ‘title’ (string) title attribute of the link.

    链接的“标题” (字符串) title 属性。

    Repeater

    中继器

    Displays the snippet of a specific repeater field.

    显示特定中继器字段的代码段。

      <?php    

    acf_snippet_the_repeater($selector, [$postId], [$args]);

    acf_snippet_the_repeater($ selector,[$ postId],[$ args]);

    ?>

    ?>

    Parameters
        

    参数
        

    $selector (string) (Required) ACF field name or ACF field key.

    $ selector (字符串)(必需) ACF字段名称或ACF字段键。

    Based on ACF get_field function.
        

    基于 ACF get_field函数
        

    $postId (integer|bool) (Optional) The post ID where the value is saved.

    $ postId (integer | bool)(可选)保存值的帖子ID。

    Default value: false (current post).
        

    默认值: false (当前发布)。
        

    $args (array) (Optional) Array of repeater output arguments.

    $ args (array)(可选)中继器输出参数的数组。

    Default value: null.

    默认值: null

    ‘template’ (string|array) Template for items inside the loop.

    “模板” (字符串|数组)循环中项目的模板。

    Arguments of get_template_part function.

    get_template_part 函数的参数。

    In the template use standard get_sub_field function.

    在模板中,使用标准的 get_sub_field函数

    ‘wrap_before’ (string) Text (HTML) before repeater items while have rows.

    “ wrap_before” (字符串)在具有行的中继器项目之前的文本(HTML)。

    ‘wrap_after’ (string) Text (HTML) after repeater items while have rows

    “ wrap_after” (字符串)带有行的重复项目后的文本(HTML)

    ’empty_html’ (string) Text (HTML) in case there are no rows in repeater.

    “ empty_html” (字符串)文本(HTML),以防中继器中没有行。

    Flexible content

    灵活的内容

    Displays the snippet of a specific flexible field.

    显示特定弹性字段的代码段。

      <?php    

    acf_snippet_the_flexible_content($selector, [$postId], [$args]);

    acf_snippet_the_flexible_content($ selector,[$ postId],[$ args]);

    ?>

    ?>

    Parameters
        

    参数
        

    $selector (string) (Required) ACF field name or ACF field key.

    $ selector (字符串)(必需) ACF字段名称或ACF字段键。

    Based on ACF get_field function.
        

    基于 ACF get_field函数
        

    $postId (integer|bool) (Optional) The post ID where the value is saved.

    $ postId (integer | bool)(可选)保存值的帖子ID。

    Default value: false (current post).
        

    默认值: false (当前发布)。
        

    $args (array) (Optional) Array of flexible content output arguments.

    $ args (array)(可选)灵活的内容输出参数的数组。

    Default value: null.

    默认值: null

    ‘templates’ (array) Array of templates for flexible content layouts.

    “模板” (数组)用于灵活内容布局的模板数组。

    In the templates use standard get_sub_field function.

    在模板中,使用标准的 get_sub_field函数

    key (string) – layout name

    (string) –布局名称

    value (string|array) arguments for get_template_part function.

    get_template_part 函数的值(string | array)参数。

    Requires Advanced Custom Fields (Pro)

    需要高级自定义字段(Pro)

    Examples

    示例

    Link field

    链接字段

      <?php    

    acf_snippet_the_link('more_info_link', false, [        

    acf_snippet_the_link('more_info_link',false,[        

    'class'=> 'link__out',        

    'class'=>'link__out',        

    ]    

    ]    

    );

    );

    ?>

    ?>

    Image field

    图片字段

      <?php    

    echo acf_snippet_get_image('logo', 'option', [        

    回声acf_snippet_get_image('logo','option',[        

    'size' => 'medium',        

    '大小'=>'中等',        

    'alt' => 'company name',        

    'alt'=>'公司名称',        

    'title' => false,        

    'title'=>否,        

    'class' => 'header__logo',        

    'class'=>'header__logo',        

    'id' => 'company-logo',        

    'id'=>'company-logo',        

    'loading' => 'fetch',        

    '正在加载'=>'获取',        

    'link' => [            

    '链接'=> [            

    'href' => get_home_url()            

    'href'=> get_home_url()            

    ]        

    ]        

    ]    

    ]    

    );

    );

    ?>

    ?>

    Repeater field

    中继器字段

      <?php    

    acf_snippet_the_repeater( 'team_members', false, [        

    acf_snippet_the_repeater('team_members',false,[        

    'template' => [ 'templates/loops/loop', 'team-member' ],        

    'template'=> [''templates / loops / loop','team-member'],        

    'wrap_before' => '

      ',        

      'wrap_before'=>'

        ',        

        'wrap_after' => '

      ',        

      'wrap_after'=>'',        

      'empty_html' => '

      ' .

      'empty_html'=>'

      '

      __( 'No team members to show.', 'web' ) .

      __('没有团队成员可以参加。','web')。

      '

      '        

      ''        

      ]    

      ]    

      );

      );

      ?>

      ?>

    Flexible content field

    灵活的内容字段

      <?php    

    acf_snippet_the_flexible_content( 'fp_content', false, [    

    acf_snippet_the_flexible_content('fp_content',false,[    

    'templates' => [        

    '模板'=> [        

    'slider' => [ 'templates/homepage/snippet', 'slider' ],        

    'slider'=> [''templates / homepage / snippet','slider'],        

    'counters' => [ 'templates/homepage/snippet', 'counters' ],        

    'counters'=> [''templates / homepage / snippet','counters'],        

    'text_block' => [ 'templates/homepage/snippet', 'text_block' ]        

    'text_block'=> ['templates / homepage / snippet','text_block']        

    ]    

    ]    

    ]

    ]

    );

    );

    ?>

    ?>

    `

    `

下载地址

https://downloads.wordpress.org/plugin/acf-snippets.zip

https://downloads.wordpress.org/plugin/acf-snippets.zip

-EOF-

AI助手支持GPT4.0