嗨,我在制作自定义post类型小部件时遇到了一个小问题。
问题是,当我想要获取我想要在内联样式中使用的字段时,它不起作用。
这是我的代码:
class Agenda_widget extends WP_Widget{
function __construct() {
parent::__construct(
\'agenda_widget\', // Base ID
\'Agenda Widget\', // Name
array(\'description\' => __( \'Details\'))
);
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance[\'title\'] = strip_tags($new_instance[\'title\']);
$instance[\'numberOfListings\'] = strip_tags($new_instance[\'numberOfListings\']);
return $instance;
}
function form($instance) {
if( $instance) {
$title = esc_attr($instance[\'title\']);
$numberOfListings = esc_attr($instance[\'numberOfListings\']);
} else {
$title = \'\';
$numberOfListings = \'\';
}
?>
<p>
<label for="<?php echo $this->get_field_id(\'title\'); ?>"><?php _e(\'Title\', \'agenda_widget\'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id(\'title\'); ?>" name="<?php echo $this->get_field_name(\'title\'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id(\'numberOfListings\'); ?>"><?php _e(\'Number of Listings:\', \'agenda_widget\'); ?></label>
<select id="<?php echo $this->get_field_id(\'numberOfListings\'); ?>" name="<?php echo $this->get_field_name(\'numberOfListings\'); ?>">
<?php for($x=1;$x<=30;$x++): ?>
<option <?php echo $x == $numberOfListings ? \'selected="selected"\' : \'\';?> value="<?php echo $x;?>"><?php echo $x; ?></option>
<?php endfor;?>
</select>
</p>
<?php
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters(\'widget_title\', $instance[\'title\']);
$numberOfListings = $instance[\'numberOfListings\'];
echo $before_widget;
if ( $title ) {
echo $before_title . $title . $after_title;
}
$this->getRealtyListings($numberOfListings);
echo $after_widget;
}
function getRealtyListings($numberOfListings) { //html
global $post;
add_image_size( \'agenda_widget_size\', 85, 45, false );
$listings = new WP_Query();
$listings->query(\'post_type=agenda&posts_per_page=\' . $numberOfListings );
if($listings->found_posts > 0) {
echo \'<ul class="agenda">\';
while ($listings->have_posts()) {
$listings->the_post();
$listItem = \'<li class="agenda-listing">\';
$listItem .= \'<header id="agenda-block">\';
$listItem .= \'<div id="agenda-info">\';
$listItem .= \'<div id="agenda-info-time">\';
$listItem .= get_field(\'time\');
$listItem .= \'</div>\';
$listItem .= \'<div id="agenda-info-title">\';
$listItem .= get_field(\'title\');
$listItem .= \'</div>\';
$listItem .= \'<div id="agenda-info-name">\';
$listItem .= get_field(\'speaker\');
$listItem .= \'</div>\';
$listItem .= \'<div id="agenda-block-image-responsive" style="get_field(\'speaker-img\', \'option\' );">\';
$listItem .= \'</div>\';
$listItem .= \'</div></header>\';
$listItem .= \'</li>\';
echo $listItem;
}
echo \'</ul>\';
wp_reset_postdata();
}else{
echo \'<p style="padding:25px;">No listing found</p>\';
}
}
} //end class Trm_Agenda_widget
register_widget(\'Agenda_widget\');
这一部分:
$listItem .= \'<div id="agenda-block-image-responsive" style="get_field(\'speaker-img\', \'option\' );">\';
不工作。
我想做的是,我想用一个acf get\\u字段函数自动将一个图像放入listitem中。
请帮忙