我知道这可能与Genesis(高级框架)无关,但对于通用WordPress,这与运行remove_action
和add_action
取决于是否存在自定义字段。我没有看到我做错的简单事情。
我要做的是显示默认的面包屑,除非存在自定义字段,如果存在,则显示自定义字段的内容。
为什么不
remove_action( \'genesis_before_loop\', \'genesis_do_breadcrumbs\' );
add_action(\'genesis_before_loop\', \'customfield_breadcrumbs\');
存在自定义字段时激发,删除默认面包屑,添加
customfield_breadcrumbs
然后
echo
我的自定义字段?
The full function:
function customfield_breadcrumbs() {
global $post;
$crumb = get_post_meta($post->ID, \'custom_breadcrumb\', true);
if ($crumb) {
remove_action( \'genesis_before_loop\', \'genesis_do_breadcrumbs\' );
add_action(\'genesis_before_loop\', \'customfield_breadcrumbs\');
echo \'<div class="breadcrumb">\';
echo get_post_meta($post->ID, \'custom_breadcrumb\', $single = true);
echo \'</div>\';
}
}
这将正确输出自定义字段的html(来自$post和$crumb),但我需要显示默认的面包屑,除非有自定义字段:
function customfield_breadcrumbs() {
global $post;
$crumb = get_post_meta($post->ID, \'custom_breadcrumb\', true);
if ($crumb) {
echo \'<div class="breadcrumb">\';
echo get_post_meta($post->ID, \'custom_breadcrumb\', $single = true);
echo \'</div>\';
}
}
这是Genesis的核心面包屑功能:
function genesis_breadcrumb( $args = array() ) {
global $_genesis_breadcrumb;
if ( ! $_genesis_breadcrumb )
$_genesis_breadcrumb = new Genesis_Breadcrumb;
$_genesis_breadcrumb->output( $args );
}
add_action( \'genesis_before_loop\', \'genesis_do_breadcrumbs\' );
它们由Genesis>>主题设置中的设置进行配置: