你使用 ACF 插件吗?
在您的页面问答
创建一个 repeater field 有 2 个字段 Question 和 Answer
<?php
$questions = get_field('questions');
if(!empty($questions)){
foreach ($questions as $key => $question) {
echo '<h3>'.$question['question'].'</h3>';
echo '<p>'.$question['answer'].'</p>';
}
}
?>
如果您使用的是 YOAST SEO 插件,那么有一个古腾堡块可以满足您的需求。
https://yoast.com/how-to-build-an-faq-page/
此 ACF 字段的 PHP 代码
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_602549386ffbd',
'title' => 'questions & answers',
'fields' => array(
array(
'key' => 'field_60254947fa15d',
'label' => 'questions',
'name' => 'questions',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => '',
'sub_fields' => array(
array(
'key' => 'field_6025494cfa15e',
'label' => 'question',
'name' => 'question',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array(
'key' => 'field_60254952fa15f',
'label' => 'answer',
'name' => 'answer',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;