WP Alchemy在模板中回显元值

时间:2011-07-11 21:29:45

标签: php wordpress meta

我正在使用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 &amp; 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>

1 个答案:

答案 0 :(得分:0)

有时您需要执行以下操作:

<?php 
    global $catPos_metabox; // sometimes you will need the global statement
    $meta = $catPos_metabox->the_meta();
?>