WP Alchemy 在模板中回显元值
我正在使用 WP Alchemy 在帖子中创建一个元框,允许用户从类别列表中进行选择。然而,一旦保存,我似乎无法回显该值。 (迪玛,希望你能帮助我!)我做错了什么?提前致谢!!!
来自functions.php:
$catPos_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_catPosition',
'title' => 'Category Position',
'template' => STYLESHEETPATH . '/assets/functions/select_meta.php',
'include_post_id' => 33
));
来自select_meta.php:
<div class="my_meta_control">
<label class="space">Space One</label><br/>
<?php $mb->the_field('space1'); ?>
<select name="<?php $mb->the_name(); ?>">
<?php
$cats = get_categories();
foreach($cats as $cat) {
$catID = $cat->term_id;
$catName = $cat->name;
?>
<option value="<?php echo $catID; ?>" <?php $mb->the_select_state($catID); ?>><?php echo $catName; ?></option>
<?php } ?>
</select> <!-- space one -->
<div class="clear"></div>
</div>
来自模板,homepage.php:
<?php
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
global $catPos_metabox;
$catPos_metabox->the_meta();
echo $catPos_metabox->the_value('spaceOne');
endwhile; endif;
?>
帖子编辑器上元框的HTML输出:
<div id="_catPosition_metabox" class="postbox " >
<div class="handlediv" title="Click to toggle">
<br />
</div>
<h3 class='hndle'><span>Category Position</span></h3>
<div class="inside">
<div class="my_meta_control">
<label class="space">Space One</label><br/>
<select name="_catPosition[space1]">
<option value="5" >Arts & Culture</option>
<option value="3" >Fashion</option>
<option value="4" selected="selected">Music</option>
<option value="1" >Uncategorized</option>
</select> <!-- space one -->
<div class="clear"></div>
</div>
<input type="hidden" name="_catPosition_nonce" value="f8c2617abe" />
</div>
I'm using WP Alchemy to create a meta box in a post that allows the user to select from a list of categories. However I can't seem to echo the value, once saved. (Dima, hoping you can help me on this!) What am I doing wrong? Thanks in advance!!!
From functions.php:
$catPos_metabox = new WPAlchemy_MetaBox(array
(
'id' => '_catPosition',
'title' => 'Category Position',
'template' => STYLESHEETPATH . '/assets/functions/select_meta.php',
'include_post_id' => 33
));
From select_meta.php:
<div class="my_meta_control">
<label class="space">Space One</label><br/>
<?php $mb->the_field('space1'); ?>
<select name="<?php $mb->the_name(); ?>">
<?php
$cats = get_categories();
foreach($cats as $cat) {
$catID = $cat->term_id;
$catName = $cat->name;
?>
<option value="<?php echo $catID; ?>" <?php $mb->the_select_state($catID); ?>><?php echo $catName; ?></option>
<?php } ?>
</select> <!-- space one -->
<div class="clear"></div>
</div>
From the template, homepage.php:
<?php
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
global $catPos_metabox;
$catPos_metabox->the_meta();
echo $catPos_metabox->the_value('spaceOne');
endwhile; endif;
?>
HTML Output for the metabox on post editor:
<div id="_catPosition_metabox" class="postbox " >
<div class="handlediv" title="Click to toggle">
<br />
</div>
<h3 class='hndle'><span>Category Position</span></h3>
<div class="inside">
<div class="my_meta_control">
<label class="space">Space One</label><br/>
<select name="_catPosition[space1]">
<option value="5" >Arts & Culture</option>
<option value="3" >Fashion</option>
<option value="4" selected="selected">Music</option>
<option value="1" >Uncategorized</option>
</select> <!-- space one -->
<div class="clear"></div>
</div>
<input type="hidden" name="_catPosition_nonce" value="f8c2617abe" />
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时您需要执行以下操作:
Sometimes you will need to do the following: