How to add fields to Blog Page/index.php by Carbon Fields

535 Views Asked by At

I am trying to add fields to Blog Page/index.php file by Carbon Fields but fields doesn't give output/echo in 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>
1

There are 1 best solutions below

0
On

If you want add fields in blog page, you can use:

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' ),
        ) );

And if you want to display the information, could use carbon_get_post_meta( $id, $name );. carbon_get_the_post_meta( $name ); is useful in the loop !

<?= carbon_get_post_meta( get_option( 'page_for_posts' ), 'crb_home_about_description' ); ?>