我是编写PHP的初学者,但致力于在WordPress中开发主题。
我不知道如何在我的头版.php中呼应我的style
选项。
我的元.php:
$meta_style = array();
$meta_style['meta_style'] = array(
'dash_icon' => 'list-view',
'title' => __('Section Settings', 'fluent'),
'description' => __('These are general section settings.','fluent'),
'context' => 'normal',
'priority' => 'high',
'option_name' => 'meta_style',
'caps' => array(),
'fields' => array(
'style' => array(
//...
'type' => 'select',
'options' => array(//option value = option label
'value' => 'white',
'value2' => 'black'
),
'multiple' => false,//allow multiple values to be selected - default false
'placeholder' => 'white'//placeholder text for the element
),
),
);
我的front-page.php
(它包裹在一个按钮中,只是看看变量是否回显(:
<button>
<? if($meta = get_post_meta($post->ID)){ if($meta['style'] == true){ echo $meta['value']; } } ?>
</button>
任何人都可以提供有关如何回显其他类型的其他示例,例如'type' => 'text'
?
我不知道你想要什么,但你应该:
1 - 查看您是否在回显正确的信息
2 - 使用var_dump()
在您的第一个代码示例中,您有一个变量$meta_style
它是一个映射。它有一个键,'meta_style'
通向下一张地图。在该内部地图中,您有钥匙'dash_icon'
等等。因此,例如,这应该回显字符串'normal'
:
echo $meta_style['meta_style']['context'];
但是,在第二个示例中,您有一个变量$meta
它也是一个映射,具有键'style'
和'value'
。你可以用以下方法回应这些内容:
echo $meta['style'];
echo $meta['value'];
根据你的例子,我不知道这些应该做什么,或者它们应该如何相关,或者它们的含义应该是什么。