Чтобы вывести поле таблицы ACF (расширенные настраиваемые поля) в конструкторе страниц Elementor, вы можете использовать следующие методы:
Метод 1: использование API ACF
<?php
$table_field = get_field('your_table_field_name');
if ($table_field) {
echo '<table>';
foreach ($table_field as $row) {
echo '<tr>';
foreach ($row as $cell) {
echo '<td>' . $cell . '</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
Метод 2: использование короткого кода ACF
[acf field='your_table_field_name']
Метод 3: использование пользовательского виджета Elementor
Вы можете создать собственный виджет Elementor для вывода поля таблицы ACF. Вот пример фрагмента кода:
<?php
namespace Elementor;
class Custom_ACF_Table_Widget extends Widget_Base {
public function get_name() {
return 'custom-acf-table-widget';
}
public function get_title() {
return 'Custom ACF Table';
}
public function get_icon() {
return 'eicon-table';
}
public function get_categories() {
return [ 'general' ];
}
protected function _register_controls() {
$this->start_controls_section(
'section_content',
[
'label' => __( 'Content', 'text-domain' ),
]
);
$this->add_control(
'table_field_name',
[
'label' => __( 'Table Field Name', 'text-domain' ),
'type' => Controls_Manager::TEXT,
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$table_field = get_field($settings['table_field_name']);
if ($table_field) {
echo '<table>';
foreach ($table_field as $row) {
echo '<tr>';
foreach ($row as $cell) {
echo '<td>' . $cell . '</td>';
}
echo '</tr>';
}
echo '</table>';
}
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Custom_ACF_Table_Widget() );
файл.