title: "图标控件" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Editor Controls - Src - Repos
图标控件
::: danger 已弃用 此控件已被弃用,推荐使用新的图标控件。 :::
Elementor 图标控件显示一个基于 Font Awesome 字体的图标选择框。该控件接受 include 或 exclude 参数来设置部分图标列表。
该控件定义在继承 Base_Data_Control 类的 Control_Icon 类中。
使用此控件时,应将 type 设置为 \Elementor\Controls_Manager::ICON 常量。
参数
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
type |
string |
icon | 控件的类型。 |
label |
string |
显示在字段上方的标签。 | |
description |
string |
显示在字段下方的描述。 | |
show_label |
bool |
true | 是否显示标签。 |
label_block |
bool |
false | 是否在单独一行显示标签。 |
separator |
string |
default | 设置控件分隔符的位置。可用值为 default、before 和 after。default 将隐藏分隔符,除非控件类型有特定的分隔符设置。before / after 会将分隔符定位在控件之前/之后。 |
options |
array |
get_icons() |
可用图标的关联数组。 |
include |
array |
要包含在选项列表中的图标类名数组。 | |
exclude |
array |
要从选项列表中排除的图标类名数组。 | |
default |
string |
默认图标名称。 |
Return Value
(string) The selected icon CSS class.
Usage
```php {14-34,43,49}
start_controls_section( 'content_section', [ 'label' => esc_html__( 'Content', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'icon', [ 'label' => esc_html__( 'Social Icons', 'textdomain' ), 'type' => \Elementor\Controls_Manager::ICON, 'include' => [ 'fa fa-facebook', 'fa fa-flickr', 'fa fa-google-plus', 'fa fa-instagram', 'fa fa-linkedin', 'fa fa-pinterest', 'fa fa-reddit', 'fa fa-twitch', 'fa fa-twitter', 'fa fa-vimeo', 'fa fa-youtube', ], 'default' => 'fa fa-facebook', ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); ?> <i class="<?php echo esc_attr( $settings['icon'] ); ?>" aria-hidden="true"></i>
<?php
}
protected function content_template(): void {
?>
<i class="{{ settings.icon }}" aria-hidden="true"></i>
<?php
}
} ```