WordPress Carbon Fields

Last update: 21 Березня, 2024

Category: WordPress

Tags: .

// to functions.php
include_once 'inc/carbon-fields.php';
Field::make( 'text', '_date', 'Date (year)' )
    ->set_width( 25 )
    ->set_attribute( 'type', 'number' )
    ->set_attribute( 'placeholder', 'Ex: "2001"' ),

 

<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;
 
add_action( 'carbon_fields_register_fields', 'vsolo_carbon' );
function vsolo_carbon() {
    
    
    
    Container::make( 'post_meta', 'Single service settings' )
        ->where( 'post_type', '=', 'service' )
        ->add_fields( array(
            Field::make( 'textarea', 'service_short_descr', 'Short description of the service' ),
            Field::make( 'image', 'service_small_image', 'Service small image for slider, 410x470px only' ),
    ) );
    Container::make( 'post_meta', 'Single location settings' )
        ->where( 'post_type', '=', 'location' )
        ->add_fields( array(
            Field::make( 'image', 'location_small_image', 'Service small image for Services page, 410x395px only' ),
    ) );
    
    
 
    Container::make( 'post_meta', 'All contacts' )
        ->where( 'post_template', '=', 'pages/contact.php' )
        ->add_fields( array(
            Field::make( 'text', 'contact_phone_main', 'Main phone' ),
            Field::make( 'text', 'contact_phone_second', 'Second phone' ),
            Field::make( 'text', 'contact_email_main', 'Main e-mail' ),
            Field::make( 'text', 'contact_email_second', 'Second e-mail' ),
            Field::make( 'text', 'contact_office_main', 'Central office location' ),
            
            Field::make( 'text', 'contact_link_facebook', 'Link to the Facebook' ),
            Field::make( 'text', 'contact_link_tw', 'Link to the Twitter' ),
            Field::make( 'text', 'contact_link_instagram', 'Link to the Instagram' ),
            Field::make( 'text', 'contact_link_linkedin', 'Link to the Linkedin' ),

            
            
            Field::make( 'text', 'truemisha_h1', 'Заголовок' ),
            Field::make( 'textarea', 'truemisha_p', 'Текст под заголовком' ),
            Field::make( 'image', 'truemisha_img', 'Фоновое изображение' ),
            Field::make( 'select', 'truemisha_page_num', 'Выберите...' )
                ->set_options( 
                    array(
                        '2' => 'Два',
                        '3' => 'Три',
                        '4' => 'Четыре',
                        '5' => 'Пять',
                    ) 
                ),
            Field::make( 'complex', 'slider_slider', 'Slider' )
            ->add_fields( array(
                    Field::make( 'text', 'title', 'Slide Title' ),
                    Field::make( 'image', 'photo', 'Slide Photo' ),
                    Field::make( 'text', 'text', 'Slide text' ),
            ) )
    ) );
 
}

/*
if( $my_meta = get_post_meta( get_the_ID(), '_truemisha_page_num', true ) ) {
    echo $meta;
}
*/

/*
if( function_exists( 'carbon_get_post_meta' ) && ( $my_meta = carbon_get_post_meta( get_the_ID(), 'contact_phone_main' ) ) ) {
    echo $meta;
}
*/

 

<?php
    if( function_exists( 'carbon_get_post_meta' ) && ( $main_phone = carbon_get_post_meta( '10', 'contact_phone_main' ) ) ) {
        $main_phone = carbon_get_post_meta( '10', 'contact_phone_main' );
        echo '<a href="callto:'.$main_phone.'" class="number"><i class="fas fa-phone"></i> '.$main_phone.'</a>';
    }
?>
if( carbon_get_post_meta( get_the_ID(), 'service_small_image' ) != '' ) {
    $service_small_image_id = carbon_get_post_meta( get_the_ID(), 'service_small_image' );
    $service_small_image = wp_get_attachment_image_url( $service_small_image_id, 'full' );
} else {
    $service_small_image = get_bloginfo('stylesheet_directory').'/assets/images/services/service-five1.jpg';
}

 

https://carbonfields.net/docs/fields-rich-text-2/?crb_version=2-2-0