-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-widgetgd_noticias.php
99 lines (83 loc) · 4.46 KB
/
wp-widgetgd_noticias.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
class NoticiasWidget extends WP_Widget
{
function NoticiasWidget()
{
$widget_ops = array('classname' => 'NoticiasWidget', 'description' => 'Noticias do Gabinete Digital, custom post type.' );
$this->WP_Widget('NoticiasWidget', 'Gabinete Digital - Noticias Lista', $widget_ops);
//$control_ops = array( 'width' => 700, 'height' => 580 );
//$this->WP_Widget('NoticiasWidget', 'Gabinete Digital - Noticias', $widget_ops, $control_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'colunas' => '3', 'qtd' => '5', 'custom_post' => '', 'categoria' => '', 'css_class' => '' ) );
$titulo = $instance['titulo'];
$colunas = $instance['colunas'];
$qtd = $instance['qtd'];
$custom_post = $instance['custom_post'];
$categoria = $instance['categoria'];
$css_class = $instance['css_class'];
?>
<p><label for="<?php echo $this->get_field_id('titulo'); ?>">Titulo: <input class="widefat" id="<?php echo $this->get_field_id('titulo'); ?>" name="<?php echo $this->get_field_name('titulo'); ?>" type="text" value="<?php echo attribute_escape($titulo); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('colunas'); ?>">Colunas: <input class="widefat" id="<?php echo $this->get_field_id('colunas'); ?>" name="<?php echo $this->get_field_name('colunas'); ?>" type="text" value="<?php echo attribute_escape($colunas); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('qtd'); ?>">Quantidade: <input class="widefat" id="<?php echo $this->get_field_id('qtd'); ?>" name="<?php echo $this->get_field_name('qtd'); ?>" type="text" value="<?php echo attribute_escape($qtd); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('custom_post'); ?>">Custom Post: <input class="widefat" id="<?php echo $this->get_field_id('custom_post'); ?>" name="<?php echo $this->get_field_name('custom_post'); ?>" type="text" value="<?php echo attribute_escape($custom_post); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('categoria'); ?>">Categoria: <input class="widefat" id="<?php echo $this->get_field_id('categoria'); ?>" name="<?php echo $this->get_field_name('categoria'); ?>" type="text" value="<?php echo attribute_escape($categoria); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('css_class'); ?>">Classe CSS: <input class="widefat" id="<?php echo $this->get_field_id('css_class'); ?>" name="<?php echo $this->get_field_name('css_class'); ?>" type="text" value="<?php echo attribute_escape($css_class); ?>" /></label></p>
<?php
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['titulo'] = $new_instance['titulo'];
$instance['colunas'] = $new_instance['colunas'];
$instance['qtd'] = $new_instance['qtd'];
$instance['custom_post'] = $new_instance['custom_post'];
$instance['categoria'] = $new_instance['categoria'];
$instance['css_class'] = $new_instance['css_class'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$args_query_post = '';
echo "<li class='span".$instance['colunas']."'>";
echo "<div class='thumbnail ultimas ".$instance['css_class']."'>";
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_titulo', $instance['titulo']);
$colunas = $instance['colunas'];
$qtd = $instance['qtd'];
$custom_post = $instance['custom_post'];
$category = $instance['categoria'];
if (!empty($titulo))
echo $before_title . $titulo . $after_title;;
if (!empty($qtd))
$args_query_post = $args_query_post . "posts_per_page=" . $qtd;
if (!empty($custom_post))
{
if ($args_query_post == '')
$args_query_post = $args_query_post . "post_type=" . $custom_post;
else
$args_query_post = $args_query_post . "&post_type=" . $custom_post;
}
if (!empty($category))
$args_query_post = $args_query_post . "&category_name=" . $category;
query_posts($args_query_post);
echo "<ul>";
if (have_posts()) :
while (have_posts()) : the_post();
echo "<li>";
echo "<a href='".get_permalink()."'>";
echo get_the_title();
echo "</a>";
echo "</li>";
endwhile;
endif;
echo "</ul>";
echo "<a href='http://gabinetedigital.rs.gov.br/news'><h4>ver mais notícias</h4></a>";
wp_reset_query();
echo "</div>";
echo "</li>";
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("NoticiasWidget");') );
?>