我正在使用CMB2 插件将额外的标题和信息放在帖子上方的我的分类页面上。我可以在后端显示字段,但前端没有显示任何内容?
我用于在后端获取信息的代码:
add_action( \'cmb2_admin_init\', \'register_taxonomy_metabox\' );
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
function register_taxonomy_metabox() {
$prefix = \'cat_headings_\';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( array(
\'id\' => $prefix . \'edit\',
\'title\' => esc_html__( \'Category Metabox\', \'cmb2\' ), // Doesn\'t output for term boxes
\'object_types\' => array( \'term\' ), // Tells CMB2 to use term_meta vs post_meta
\'taxonomies\' => array( \'category\' ), // Tells CMB2 which taxonomies should have these fields
// \'new_term_section\' => true, // Will display in the "Add New Category" section
) );
$cmb_term->add_field( array(
\'name\' => esc_html__( \'Category Headings\', \'cmb2\' ),
\'desc\' => esc_html__( \'Sub Heading and Sub Title\', \'cmb2\' ),
\'id\' => $prefix . \'cat_info\',
\'type\' => \'title\',
\'on_front\' => false,
) );
$cmb_term->add_field( array(
\'name\' => esc_html__( \'Category Sub Heading\', \'cmb2\' ),
\'desc\' => esc_html__( \'Sub Heading\', \'cmb2\' ),
\'id\' => $prefix . \'cat-sub-heading\',
\'type\' => \'text\',
) );
}
以及我用来获取正面信息的代码:
add_action(\'genesis_before_loop\', \'cat_sub_title\', 5 );
function cat_sub_title($term_id) {
$catsubhead = get_term_meta( $term_id, \'cat_headings_cat-sub-heading\', true );
if ( is_category() ) {
if ( $catsubhead ) {
printf( \'<h2 class="sub-heading">%s</h2>\', $catsubhead );
}
}
}
我已经能够在前面回显一些html,所以我知道我可能对CMB2做了一些错误,我只是不确定是什么?任何人都会非常感谢您的帮助>
谢谢