douseda0009 2011-07-11 21:29
浏览 8
已采纳

WP Alchemy在模板中回显元值

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 &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条回答 默认 最新

  • down2323 2011-07-11 22:06
    关注

    Sometimes you will need to do the following:

    <?php 
        global $catPos_metabox; // sometimes you will need the global statement
        $meta = $catPos_metabox->the_meta();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。