Ниже есть код, в котором ошибка присутствует, благодаря которой не выводятся новости.
Пробовал что то менять, ничего не выходит.
Посмотрите пожалуйста:
PHP:
скопировать код в буфер обмена
<?PHP class getlastnews extends WP_Widget { /** constructor -- name this the same as the class above */ function getlastnews() { $widget_ops = array( 'description' => __ ('Вывод последних новостей') ); $control_ops = array( 'width' => 200, 'height' => 200, 'id_base' => 'getlastnews_widget' ); $this->WP_Widget( 'getlastnews_widget', __('Новости'), $widget_ops, $control_ops ); } /** @see WP_Widget::widget -- do not rename this */ function widget($args, $instance) { $cat_id = $instance['cat_id']; $number_entries = $instance['number_entries']; $lastnews = new WP_Query('cat=<?PHP echo $cat_id ?>&showposts=<?PHP echo $number_entries ?>&orderby=date'); ?> <h2>Новости</h2> <div class="widget"> <?PHP while ($lastnews->have_posts()) : $lastnews->the_post(); ?> <div class="news"> <div class="clearly"><div> <div class="date_container"><span class="date"><?PHP the_time('d.m.Y'); ?></span></div> <div class="clearly"><div> <span class="txt_conteiner"><a href="<?PHP the_permalink() ?>" title="<?PHP the_title(); ?>"> <span class="img_conteiner"> <?PHP the_post_thumbnail (array(40 ,40 )); ?></span> <?PHP the_title(); ?></a> </span> </div> <?PHP endwhile; ?> </div> <div class="clearly"><div> <?PHP } /** @see WP_Widget::update -- do not rename this */ function update($new_instance, $old_instance) { $instance = $old_instance; $instance['cat_id'] = strip_tags($new_instance['cat_id']); $instance['number_entries'] = strip_tags($new_instance['number_entries']); return $instance; } /** @see WP_Widget::form -- do not rename this */ function form($instance) { $defaults = array( 'cat_id' => __ ('1'), 'number_entries' => __ ('5') ); $cat_id = esc_attr($instance['cat_id']); $number_entries = esc_attr($instance['number_entries']); ?> <p> <label for="<?PHP echo $this->get_field_id('cat_id'); ?>"><?PHP _e('ID Рубрики:'); ?></label> <input class="widefat" id="<?PHP echo $this->get_field_id('cat_id'); ?>" name="<?PHP echo $this->get_field_name('cat_id'); ?>" type="text" value="<?PHP echo $cat_id; ?>" /> </p> <p> <label for="<?PHP echo $this->get_field_id('number_entries'); ?>"><?PHP _e('Количество записей:'); ?></label> <input class="widefat" id="<?PHP echo $this->get_field_id('number_entries'); ?>" name="<?PHP echo $this->get_field_name('number_entries'); ?>" type="text" value="<?PHP echo $number_entries; ?>" /> </p> <?PHP } } // end class example_widget add_action ('widgets_init', create_function('', 'return register_widget("getlastnews");'));?>
Вот код работающего вывода новостей, но он без настроек вывода количества и выбора рубрики
PHP:
скопировать код в буфер обмена
<?PHP // Добавляем виджет новостей function getlastnews() { $lastnews = new WP_Query('cat=1&showposts=15&orderby=date'); ?> <h2>Новости</h2> <div class="widget"> <?PHP while ($lastnews->have_posts()) : $lastnews->the_post(); ?> <div class="news"> <div class="clearly"><div> <div class="date_container"><span class="date"><?PHP the_time('d.m.Y'); ?></span></div> <div class="clearly"><div> <span class="txt_conteiner"><a href="<?PHP the_permalink() ?>" title="<?PHP the_title(); ?>"> <span class="img_conteiner"> <?PHP the_post_thumbnail (array(40 ,40 )); ?></span> <?PHP the_title(); ?></a> </span> </div> <?PHP endwhile; ?> </div> <div class="clearly"><div> <?PHP }; ?>
|