Wordpress 致命错误:调用成员函数\u meta()wpalchemy
从single.php调用_meta()时出错,我使用的是wordpress 3.4.1和wordpress Alchemy Metabox类1.4.17,my functions.phpWordpress 致命错误:调用成员函数\u meta()wpalchemy,wordpress,meta-boxes,Wordpress,Meta Boxes,从single.php调用_meta()时出错,我使用的是wordpress 3.4.1和wordpress Alchemy Metabox类1.4.17,my functions.php include_once ( get_template_directory() .'/metaboxes/setup.php'); include_once( get_template_directory() .'/metaboxes/custom-spec.php'); my setup.php
include_once ( get_template_directory() .'/metaboxes/setup.php');
include_once( get_template_directory() .'/metaboxes/custom-spec.php');
my setup.php
include_once WP_CONTENT_DIR . '/wpalchemy/MetaBox.php';
include_once WP_CONTENT_DIR . '/wpalchemy/MediaAccess.php';
// include css to help style our custom meta boxes
add_action( 'init', 'my_metabox_styles' );
function my_metabox_styles()
{
if ( is_admin() )
{
wp_enqueue_style( 'wpalchemy-metabox', get_stylesheet_directory_uri() . '/metaboxes/meta.css' );
}
}
$wpalchemy_media_access = new WPAlchemy_MediaAccess();
custom-spec.php
<?php
$custom_mb = new WPAlchemy_MetaBox(array
(
'id' => '_custom_meta',
'title' => 'My Custom Meta',
'template' => get_stylesheet_directory() . '/metaboxes/custom-meta.php',
));
错误是:致命错误:对C:\wamp\www\wp\wp content\themes\twentyeleven\single.php第19行中的非对象调用成员函数\u meta()
请帮助我找到错误原因这里的主要问题是全局$custom\u mb很可能什么都不是。因此,要求它有一个值是导致错误的原因 看起来您的代码是正确的,如下例所示: 使用
print\r($custom\u mb)代码>在全局变量之后查看它包含的内容。如果没什么的话,你知道有些事情不对
此外,您所说的在循环内部的代码应该就在循环外部
(更新)修复:添加global$custom\u mb
到新php页面的顶部。我不知道wpalchemy,但它不在插件目录中吗?您包括/wp content/wpacchemy/…
而不是/wp content/plugin/wpacchemy/…
很好!在处理独立的php文件时,global
“技巧”应该一直在你的脑海中。感谢它的工作,我忘了在custom-spec.php中放置global$custom_mb。
<?php //inside loop.......... ?>
<?php global $custom_mb ?>
<?php echo $custom_mb->the_meta();?>