metabolism/carbon-fields-urlpicker

Carbon Fields 扩展,添加了 URL 选择器字段类型。

安装次数: 24

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 18

语言:JavaScript

类型:wordpress-plugin

3.0.10 2024-01-23 09:40 UTC

This package is auto-updated.

Last update: 2024-09-23 10:59:10 UTC


README

(这是 Carbon Fields 插件的扩展)

您可以通过 composer 安装它

composer require iamntz/carbon-fields-urlpicker --prefer-dist

如果您从源代码安装,请确保运行 npm installnpm run production 以编译资源。

返回值

该字段将返回以下值的关联数组

url: the actual URL
anchor: the text anchor (might be blank)
blank: wether the link should open in a new window or not

示例

注册字段

与其它 Carbon Fields 字段一样,此代码应放在您的 functions.php 文件中。唯一不同的是,类型为 urlpicker

use Carbon_Fields\Container;
use Carbon_Fields\Field;

add_action( 'carbon_fields_register_fields', 'crb_url_picker_test' );

function crb_url_picker_test() {
  Container::make( 'post_meta', 'URL Picker Test' )
    ->add_fields( array(
      Field::make( 'urlpicker', 'crb_my_link', 'URL Picker Test' )
      ->set_help_text( "This is a test of the URL picker." )
    ));
}

使用字段值

<?php $my_link = carbon_get_the_post_meta( 'crb_my_link' ); ?>
<a href="<?= $my_link[url] ?>"<?= ( $my_link[blank] ? ' target="_blank"' : '') ?>><?= $my_link[anchor] ?></a>

请注意,blank 字段将返回 01,具体取决于“在新标签页中打开链接”旁边的复选框是否勾选。

觉得这很有用吗?

您可以通过 托管(并获得10美元信用额度),捐赠 或购买我的 礼物