Hi @giray,
Yes, this is something you can do with Carbon Fields.
If you have a specific list of fields that will never change you can use the following snippets:
Add this to the top of your theme’s functions.php file:
<?php
use Carbon_Fields\Field;
use Carbon_Fields\Container;
add_action( 'carbon_register_fields', 'crb_attach_post_meta' );
function crb_attach_post_meta() {
Container::make( 'post_meta', __( 'Post Options', 'crb' ) )
->show_on_post_type( 'post' )
->add_fields( array(
Field::make( 'separator', 'crb_reference_separator', 'Reference' ),
Field::make( 'text', 'crb_reference_title', 'Title' )
->set_width( 25 ),
Field::make( 'text', 'crb_reference_year', 'Year' )
->set_width( 25 ),
Field::make( 'text', 'crb_reference_name', 'Name' )
->set_width( 25 ),
Field::make( 'text', 'crb_reference_country', 'Country' )
->set_width( 25 ),
) );
}
Add this to your post loop where you wish to output the combined reference:
<?php
$reference = array(
carbon_get_the_post_meta( 'crb_reference_title' ),
'<strong>' . carbon_get_the_post_meta( 'crb_reference_year' ) . '</strong>',
carbon_get_the_post_meta( 'crb_reference_name' ),
'<strong><em>' . carbon_get_the_post_meta( 'crb_reference_country' ) . '</em></strong>',
);
echo '<p>' . implode( ', ', $reference ) . '.</p>';
?>
Alternatively, if you wish to have multiple references per post you can wrap the 4 fields in a complex field. If this is the case use these snippets instead:
Add this to the top of your theme’s functions.php file:
<?php
use Carbon_Fields\Field;
use Carbon_Fields\Container;
add_action( 'carbon_register_fields', 'crb_attach_post_meta' );
function crb_attach_post_meta() {
Container::make( 'post_meta', __( 'Post Options', 'crb' ) )
->show_on_post_type( 'post' )
->add_fields( array(
Field::make( 'complex', 'crb_references', 'References' )
->add_fields( array(
Field::make( 'text', 'title', 'Title' )
->set_width( 25 ),
Field::make( 'text', 'year', 'Year' )
->set_width( 25 ),
Field::make( 'text', 'name', 'Name' )
->set_width( 25 ),
Field::make( 'text', 'country', 'Country' )
->set_width( 25 ),
) )
) );
}
Add this to your post loop where you wish to output the combined reference:
<?php
$references = carbon_get_the_post_meta( 'crb_references', 'complex' );
foreach ( $references as $reference_values ) {
$reference = array(
$reference_values['title'],
'<strong>' . $reference_values['year'] . '</strong>',
$reference_values['name'],
'<strong><em>' . $reference_values['country'] . '</em></strong>',
);
echo '<p>' . implode( ', ', $reference ) . '.</p>';
}
?>