WPAlchemy - 第3行的致命错误

时间:2012-09-21 17:27:53

标签: php wordpress fatal-error

我的代码第3行有一些错误,我似乎无法弄明白。下面是它输出的错误以及我的代码。

致命错误:在第3行的非对象上调用成员函数the_meta()

<?php $meta = $custom_metabox->the_meta('description', TRUE); 
if (!empty($meta)): 
echo '<p class="description">'.$meta['description'].'</p>'; ?>
<?php endif; ?>

<br>

<ul id="process"><span>Process: </span></ul>

<br>

<ul class="credits">
<?php if(the_meta()) { the_meta(); } ?>
    <li class="shorturl"><span>Short Url: </span>
        <div id="d_clip_container">
            <input id="fe_text" onChange="clip.setText(this.value)" type="text" value="<?php echo bitly(); ?>" />
        <div id="d_clip_button" class="my_clip_button"></div>
        </div>
    </li>
    <li class="save"><span>Save: </span> <a class="gimmebar" href="#">Gimme Bar</a></li>                
</ul>
</div> <!-- End Info -->

<?php get_search_form(); ?>

这是第3行     <?php $meta = $custom_metabox->the_meta('description', TRUE);

1 个答案:

答案 0 :(得分:1)

您可能在代码中遗漏了一些内容。请看第3行:$custom_metabox->the_meta('description', TRUE) ..现在看第13行:if(the_meta()) { the_meta(); }在您的代码的一部分中,您使用了{{1作为一个成员函数,在另一部分你已经将它用作一般函数..这怎么可能是正确的?首先确保the_meta()是否属于某个班级,而不是正确地调用它......

更新:

好的一些在wpalchemy手册中搜索,我得到了问题所在......你应该在the_meta()中构建$custom_metabox作为WPAlchemy_MetaBox,以便能够将元数据包含在模板.. Read Here ..

示例:

functions.php

现在,如果你有这个功能,你应该在模板中包含这些功能......

手册中提供的示例代码:

$custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'template' => STYLESHEETPATH . '/custom/meta.php'
));

*请注意顶部的// usually needed global $custom_metabox; // get the meta data for the current post $custom_metabox->the_meta(); // set current field, then get value $custom_metabox->the_field('name'); $custom_metabox->the_value(); // get value directly $custom_metabox->the_value('description'); // loop a set of fields while($custom_metabox->have_fields('authors')) { $custom_metabox->the_value(); } // loop a set of field groups while($custom_metabox->have_fields('links')) { $custom_metabox->the_value('title'); $custom_metabox->the_value('url'); if ($custom_metabox->get_the_value('nofollow')) echo 'is-nofollow'; $custom_metabox->the_value('target'); } * *此外,您应该像global $custom_metabox;一样使用它,而不仅仅是普通的$custom_metabox->the_meta(); ..