我们正在使用WordPress网站中的自定义字段的碳域插件,但问题是WordPress不能存储碳自定义字段的修订。有人能帮上忙吗?
发布于 2017-08-08 20:26:02
有两种方法可以在主题中包含碳场插件。1)在plugin文件夹中添加碳场插件并激活。2)在主题文件夹中添加碳域插件文件夹。
/* Integrating Carbon Fields Plugin */
use Carbon_Fields\Container;
use Carbon_Fields\Field;
add_action( 'after_setup_theme', 'crb_setup_theme' );
function crb_setup_theme() {
// check if Carbon Fields is not already installed
if ( ! class_exists( "\\Carbon_Fields\\Field\\Field" ) ) {
require( get_template_directory() . '/carbon-fields/carbon-fields-plugin.php' );
}
}
add_action('carbon_register_fields', 'crb_register_custom_fields');
function crb_register_custom_fields() {
require get_template_directory() . '/theme_option/meta_boxes.php';
}在meta_boxes.php文件中,您需要创建元字段。像这样
use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make('post_meta', 'Date Container') // New Added
->show_on_post_type(array('hotel')) // Hotel is custom post type
->add_fields(array(
Field::make('complex','hotel_details_page_content', 'Images & Content')
->add_fields('Entry Container', array(
Field::make("separator", "crb_image_options", "Image Entry"),
Field::make("image", "row_images", "Image"),
Field::make("text", "row_image_headlines", "Image Headline"),
Field::make("text", "image_row_subheadlines", "Image Sub Headline"),
Field::make("separator", "crb_style_options", "Content Entry"),
Field::make("text", "content_titles", "Title"),
Field::make("rich_text", "content_datas", "Content"),
)),
));
Container::make('post_meta', 'Gallery Container')
->show_on_post_type('gallery') // Gallery is custom post type
->add_fields(array(
Field::make('complex','galleryimages', 'Gallery')
->add_fields('Gallery Entry', array(
Field::make("image", "gallery_images", "Upload Image"),
))
));通过这种方式,您可以创建多个字段作为中继器,并且还可以保存值。
并在前端获取值。
$carbvalue= carbon_get_post_meta(get_the_ID(), 'hotel_details_page_content', 'complex');
foreach ($carbvalue as $carbonvalues) {
$herorimageid = $carbonvalues['row_images'];
$heroimage = wp_get_attachment_url($herorimageid);
?>
<img src="<?php echo $heroimage; ?>" sizes="100vw" alt="heroimage" />
<?php
echo $carbonvalues['row_image_headlines'];
}https://stackoverflow.com/questions/42574645
复制相似问题