【问题标题】:WPAlchemy - Fatal Error on line 3 [closed]WPAlchemy - 第 3 行的致命错误 [关闭]
【发布时间】:2012-09-21 17:27:52
【问题描述】:

我的代码第 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 行 &lt;?php $meta = $custom_metabox-&gt;the_meta('description', TRUE);

【问题讨论】:

  • 答案就在错误信息中——$custom_metabox 不是一个对象。它是在哪里定义的?
  • 确保包含/加载了 $meta 引用的类或对象
  • 这是我正在使用的插件,它只在我在搜索页面上时抛出错误。否则它工作正常。
  • 你把这个放在哪个wordpress模板文件里了?
  • 我正在为我的自定义元框使用 WPAlchemy。该插件位于主题文件夹(/wp-content/wpalchemy)之前的目录中。

标签: php wordpress fatal-error


【解决方案1】:

您可能在代码中遗漏了某些内容。查看第 3 行:$custom_metabox-&gt;the_meta('description', TRUE).. 现在查看第 13 行:if(the_meta()) { the_meta(); } 在部分代码中,您使用了 the_meta() 作为成员函数在另一部分中,您将其用作一般功能。这怎么可能是正确的?首先确定the_meta() 是否在一个类中,然后正确调用它...

更新:

好的,在 wpalchemy 手册中进行一些搜索,我得到了问题所在..您应该在 functions.php 中将 $custom_metabox 构造为 WPAlchemy_MetaBox,以便能够在模板中包含元框.. @987654321 @..

示例:

$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-&gt;the_meta(); 一样使用它,而不仅仅是简单的the_meta();..

【讨论】:

  • 我真的不知道该怎么做,因为我离开发人员还很远。另外,我很确定当我粘贴这段代码时,它是由插件作者提供的。
  • @ChristopherBurton 查看更新!
  • 非常感谢您帮我看这些,Miro。真的很感激。我会尽快处理并接受您的回答。
  • 我最终关注了这个tutorial 并让它工作了。感谢您的帮助
  • @ChristopherBurton 不客气。
猜你喜欢
  • 2012-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-25
  • 1970-01-01
  • 1970-01-01
  • 2023-01-06
相关资源
最近更新 更多