如何通过Carbon Fields向博客页面/index.php添加字段

问题描述 投票:0回答:1

我正在尝试通过 Carbon Fields 将字段添加到博客页面/index.php 文件,但字段在 index.php 中没有给出输出/回显

carbon.php

Container::make( 'post_meta', __( 'Blog Page Settings','carbon' ) )
        ->where( 'post_template', '=', 'index.php' )

        ->add_tab( __( 'Page Header Section','carbon' ), array(
            Field::make( 'text', 'blog_page_header_title', __( 'Title','carbon' ) )->set_width( 100 ),
            Field::make( 'text', 'blog_page_header_sub_title', __( 'Sub Title','carbon' ) )->set_width( 100 ),
        ) );

index.php

<h4><?php echo esc_html(carbon_get_the_post_meta('blog_page_header_title')); ?></h4>
<h1><?php echo esc_html(carbon_get_the_post_meta('blog_page_header_sub_title')); ?></h1>
php wordpress meta-boxes carbon-fields
1个回答
0
投票

如果您想在博客页面添加字段,您可以使用:

Container::make( 'post_meta', __( 'Home', 'crb' ) )
    ->where( 'post_id', '=', get_option( 'page_for_posts' ) )

    ->add_tab( 'About', array(
        Field::make( 'rich_text', 'crb_home_about_description', 'Description' ),
        ) );

如果你想显示信息,可以使用

carbon_get_post_meta( $id, $name );
carbon_get_the_post_meta( $name );
在循环中很有用!

<?= carbon_get_post_meta( get_option( 'page_for_posts' ), 'crb_home_about_description' ); ?>
© www.soinside.com 2019 - 2024. All rights reserved.