当我使用wordpress 3.4.1和WordPress炼金术Metabox Class 1.4.17 (我的functions.php )从single.php调用the_meta()时,出现了错误
include_once ( get_template_directory() .'/metaboxes/setup.php');
include_once( get_template_directory() .'/metaboxes/custom-spec.php');我的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',
));和single.php
<?php //inside loop.......... ?>
<?php global $custom_mb ?>
<?php echo $custom_mb->the_meta();?>错误是:致命错误:在第19行的C:\wamp\www\wp\wp-content\themes\twentyeleven\single.php中对非对象调用成员函数the_meta()
请帮我找出错误的原因
发布于 2012-07-24 17:51:05
这里的主要问题是,全局$custom_mb很可能什么都不是。因此,要求它有一个值是导致错误的原因。
根据下面的示例,看起来您确实拥有了正确的代码:http://www.farinspace.com/wpalchemy-metabox/
在全局变量后使用print_r($custom_mb);来查看它包含的内容。如果没什么,你就知道有什么不对劲。
此外,您所说的在循环内的代码应该恰好在它的外部。
(更新)修复:将global $custom_mb;添加到新php页面的顶部。
https://stackoverflow.com/questions/11626350
复制相似问题