与acf的Wordpress小部件

时间:2017-10-05 11:50:16

标签: php wordpress

我在functions.php中创建了一个小部件,所有规则,高级自定义字段在其中创建自己的字段,我输入内容,我保存,在前端显示内容,但是当我再次打开小部件来编辑内容,我有空白的用户字段。代码有什么问题?也许在现场更新我有错误?

if(!class_exists('CtaWidget')) {

  class CtaWidget extends WP_Widget {

    /**
    * Sets up the widgets name etc
    */
    public function __construct() {
      $widget_ops = array(
        'classname' => 'cta_widget',
        'description' => 'CTA Widget built with ACF Pro',
      );
      parent::__construct( 'cta_widget', 'CTA Widget', $widget_ops );
    }

    /**
    * Outputs the content of the widget
    *
    * @param array $args
    * @param array $instance
    */
    public function widget( $edit_content ) {
        ?>
    }
     <div class="spoiler-container">
<div class="up-spoiler"></div>
<div class="spoiler-parent">
<div class="advant-section title-spoiler">
<?php if( get_field('spoiler_title') ): ?>
<h2><?php the_field('spoiler_title'); ?></h2>
<?php endif; ?>
</div>
<div class="spoiler-overlay"></div>
<div class="spoiler-children">
 <?php if( have_rows('spoiler') ): ?>
    <?php while( have_rows('spoiler') ): the_row(); 
     $edit_content = get_sub_field('edit_content');
     ?>
<?php echo $edit_content; ?>
 <?php endwhile; ?>
<?php endif; ?>

</div>
<div class="spoiler-btn"><i class="fa fa-angle-double-down" aria-hidden="true"></i></div>
</div>
</div> <?php
    }

    /**
     * Outputs the options form on admin
     *
     * @param array $instance The widget options
     */
    public function form( $instance ) {
        // outputs the options form on admin
    }

    /**
     * Processing widget options on save
     *
     * @param array $new_instance The new options
     * @param array $old_instance The previous options
     *
     * @return array
     */
    public function update( $edit_content ) {
        return $edit_content;
    }

  }

}

/**
 * Register our CTA Widget
 */
function register_cta_widget()
{
  register_widget( 'CtaWidget' );
}
add_action( 'widgets_init', 'register_cta_widget' );

0 个答案:

没有答案