WP Alchemy 在模板中回显元值

发布于 2024-11-19 16:05:38 字数 2397 浏览 0 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃素的狼 2024-11-26 16:05:38

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

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

Sometimes you will need to do the following:

<?php 
    global $catPos_metabox; // sometimes you will need the global statement
    $meta = $catPos_metabox->the_meta();
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文