首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPAlchemy -第3行出现致命错误

WPAlchemy -第3行出现致命错误
EN

Stack Overflow用户
提问于 2012-09-22 01:27:53
回答 1查看 536关注 0票数 0

我的代码的第三行有一些错误,我似乎找不出来。下面是它输出的错误,还有我的代码。

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

代码语言:javascript
复制
<?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);

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-22 01:36:51

您可能在代码中遗漏了一些东西..看一下第3行:$custom_metabox->the_meta('description', TRUE)..现在看一下第13行:if(the_meta()) { the_meta(); }在一部分代码中,您将the_meta()用作成员函数,而在另一部分代码中,您将其用作常规函数。这怎么可能是对的呢?首先确定the_meta()是否在类中,然后正确调用它……

更新:

好的,在wpalchemy手册中搜索一下,我找到了问题所在..您应该将$custom_metabox构造为functions.php中的WPAlchemy_MetaBox,以便能够在模板中包含元数据。Read Here..

示例:

代码语言:javascript
复制
$custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'template' => STYLESHEETPATH . '/custom/meta.php'
));

当你有了它,你就应该在你的模板中包含这些函数……

手册中提供的示例代码:

代码语言:javascript
复制
// 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();一样使用它,而不仅仅是普通的the_meta();。。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12535286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档