{
$widget_options = array(
'classname' => 'catalog_widget',
'description' => 'Виджет Каталог',
);
parent::__construct( 'catalog_widget', 'Виджет Каталог', $widget_options );
}
public function widget( $args, $instance ) {
$widget_id = $args['widget_id'];
$title = apply_filters( 'widget_title', $instance['title'] );
?>
<section class="catalog" id="catalog">
<div class="container">
<h2 class="title"><?php echo $title; ?></h2>
<div class="row">
<?php
$catalog_category = get_field('catalog_category');
$posts = get_posts( array(
'numberposts' => -1,
'category_name' => $catalog_category,
'orderby' => 'date',
'order' => 'ASC',
'post_type' => 'post',
'suppress_filters' => true,
) );
foreach( $posts as $post ){
setup_postdata( $post );
?>
<div class="col-lg-3 col-md-6 col-12">
<div class="card">
<?php $card_img = get_field('card_img'); ?>
<img src="<?php if($card_img){echo $card_img['url'];}?>" alt="<?php $card_img['alt'];?>">
<h3 class="card-title"><?php the_title(); ?></h3>
<button class="btn btn__card" data-modal="order"><?php the_field('catalog_btn');?></button>
</div>
</div>
</div>
</div>
</section>
<?php
}
wp_reset_postdata();
?>
<?php
}
public function form( $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Заголовок: </label>
<input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" />
</p><?php
}
}
?>
в functions.php подключили?
Виджет выводится, но некорректно
Обсуждают сегодня