高级自定义字段隐藏字段
Advanced Custom Fields Hidden Field
我在 Wordpress 站点中使用 ACF 为自定义 post 类型配置一些选项,并使用 ACF 唯一 ID 插件生成一个字段,为该字段构建唯一 ID。它的配置非常基本:
class acf_field_unique_id extends acf_field {
function __construct() {
/*
* name (string) Single word, no spaces. Underscores allowed
*/
$this->name = 'unique_id';
/*
* label (string) Multiple words, can include spaces, visible when selecting a field type
*/
$this->label = __('Unique ID', 'acf-unique_id');
/*
* category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME
*/
$this->category = 'layout';
/*
* l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via:
* var message = acf._e('unique_id', 'error');
*/
$this->l10n = array(
);
// do not delete!
parent::__construct();
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field (array) the $field being rendered
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field (array) the $field being edited
* @return n/a
*/
function render_field( $field ) {
?>
<input type="text" readonly="readonly" name="<?php echo esc_attr($field['name']) ?>" value="<?php echo esc_attr($field['value']) ?>" />
<?php
}
}
虽然所有这些都很好用,但 ID 字段被设计为内部 ID 标记,而不是最终用户需要在 Wordpress 中看到的东西。有没有办法隐藏与此字段关联的列,这样我就不会丢失宝贵的屏幕空间?该列占宽度的 33%,由于它用于不需要的字段,因此占用太多 space。我试过将它隐藏在 CSS 和 Javascript 中,但出于某种原因,这会使结束列(重复行号和 +/- 符号)变得更大。
你试过把它改成input[type="hidden"]
吗?
function render_field( $field ){
echo '<input type="hidden" readonly="readonly" name="'. esc_attr( $field['name'] ) .'" value="'. esc_attr( $field['value'] ) .'" />';
}
我在 Wordpress 站点中使用 ACF 为自定义 post 类型配置一些选项,并使用 ACF 唯一 ID 插件生成一个字段,为该字段构建唯一 ID。它的配置非常基本:
class acf_field_unique_id extends acf_field {
function __construct() {
/*
* name (string) Single word, no spaces. Underscores allowed
*/
$this->name = 'unique_id';
/*
* label (string) Multiple words, can include spaces, visible when selecting a field type
*/
$this->label = __('Unique ID', 'acf-unique_id');
/*
* category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME
*/
$this->category = 'layout';
/*
* l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via:
* var message = acf._e('unique_id', 'error');
*/
$this->l10n = array(
);
// do not delete!
parent::__construct();
}
/*
* render_field()
*
* Create the HTML interface for your field
*
* @param $field (array) the $field being rendered
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field (array) the $field being edited
* @return n/a
*/
function render_field( $field ) {
?>
<input type="text" readonly="readonly" name="<?php echo esc_attr($field['name']) ?>" value="<?php echo esc_attr($field['value']) ?>" />
<?php
}
}
虽然所有这些都很好用,但 ID 字段被设计为内部 ID 标记,而不是最终用户需要在 Wordpress 中看到的东西。有没有办法隐藏与此字段关联的列,这样我就不会丢失宝贵的屏幕空间?该列占宽度的 33%,由于它用于不需要的字段,因此占用太多 space。我试过将它隐藏在 CSS 和 Javascript 中,但出于某种原因,这会使结束列(重复行号和 +/- 符号)变得更大。
你试过把它改成input[type="hidden"]
吗?
function render_field( $field ){
echo '<input type="hidden" readonly="readonly" name="'. esc_attr( $field['name'] ) .'" value="'. esc_attr( $field['value'] ) .'" />';
}