首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在wordpress中保存碳字段的修订?

如何在wordpress中保存碳字段的修订?
EN

Stack Overflow用户
提问于 2017-03-03 17:05:52
回答 1查看 524关注 0票数 0

我们正在使用WordPress网站中的自定义字段的碳域插件,但问题是WordPress不能存储碳自定义字段的修订。有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2017-08-08 20:26:02

有两种方法可以在主题中包含碳场插件。1)在plugin文件夹中添加碳场插件并激活。2)在主题文件夹中添加碳域插件文件夹。

代码语言:javascript
复制
  /* 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文件中,您需要创建元字段。像这样

代码语言:javascript
复制
    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"),
        ))
    ));

通过这种方式,您可以创建多个字段作为中继器,并且还可以保存值。

并在前端获取值。

代码语言:javascript
复制
$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'];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42574645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档