PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- add_action( 'widgets_init', 'getlastnews' );
- function getlastnews() {
- register_widget( 'getlastnews' );
- }
- class getlastnews extends WP_Widget {
- function getlastnews() {
- $widget_ops = array( 'classname' => 'getlastnews', 'description' => __('Вывод последних новостей из рубрики') );
- $this->WP_Widget( 'getlastnews_widget', __('Новости'), $widget_ops, $control_ops );
- $lastnews = new WP_Query('cat=%1$s&showposts=15&orderby=date', $category_id); ?>
- <h2>Новости</h2>
- <ul>
- <li>
- <div class="widget">
- <?PHP while ($lastnews->have_posts()) : $lastnews->the_post(); ?>
- <div class="news">
- <div class="date_container"><span class="date"><?PHP the_time('d.m.Y'); ?></span></div>
- <span class="txt_conteiner"><a href="<?PHP the_permalink() ?>" title="<?PHP the_title(); ?>">
- <?PHP the_title(); ?></a>
- </span>
- </div>
- <?PHP endwhile; ?>
- </div>
- </li>
- </ul>
- <?PHP
- function widget( $args, $instance ) {
- //Our variables from the widget settings.
- $category_id = $instance['category_id'];
- echo $before_widget;
- // Изменяем рубрику
- if ( $category_id )
- echo $after_widget;
- }
- //Обновление виджета
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- //Strip tags from title and name to remove HTML
- return $instance;
- }
- function form( $instance ) {
- //Устанавливаем параметры по умолчанию.
- <p>
- <label for="<?PHP echo $this->get_field_id( 'category_id' ); ?>"><?PHP _e('ID Рубрики:'); ?></label>
- <input id="<?PHP echo $this->get_field_id( 'category_id' ); ?>" name="<?PHP echo $this->get_field_name( 'category_id' ); ?>" value="<?PHP echo $instance['category_id']; ?>" style="width:80%;" />
- </p>
- <?PHP
- }
- } ?>