-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-oquegd-widget.php
165 lines (133 loc) · 6.66 KB
/
wp-oquegd-widget.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
class OqueListaWidget extends WP_Widget
{
function OqueListaWidget()
{
$widget_ops = array('classname' => 'OqueListaWidget', 'description' => 'O que é? Gabinete Digital. Lista de documentos O que é?' );
$this->WP_Widget('OqueListaWidget', 'Gabinete Digital - O que é? Lista', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'colunas' => '3', 'qtd' => '5', 'css_class' => '' ) );
$titulo = $instance['titulo'];
$colunas = $instance['colunas'];
$qtd = $instance['qtd'];
$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('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('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('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['css_class'] = $new_instance['css_class'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$args_query_post = '';
$txtreturn = '';
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_titulo', $instance['titulo']);
$colunas = $instance['colunas'];
$qtd = $instance['qtd'];
$custom_post = 'oquegd_oque';
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;
}
query_posts($args_query_post);
$txtreturn .= "<div class='publicacoes ".$instance['css_class']."'>";
$txtreturn .= "<h3>".$titulo."</h3>";
$txtreturn .= "<ul class='thumbnails'>";
if (have_posts()) :
while (have_posts()) : the_post();
$txtreturn .= "<li class='span".$colunas."'>";
$txtreturn .= "<div class='thumbnail'>";
$txtreturn .= "<h4>".get_the_title()."</h4>";
$txtreturn .= get_the_content();
$txtreturn .= "</div>";
$txtreturn .= "</li>";
endwhile;
endif;
wp_reset_query();
$txtreturn .= "</ul>";
$txtreturn .= "</div>";
echo $txtreturn;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("OqueListaWidget");') );
class OqueWidget extends WP_Widget
{
function OqueWidget()
{
$widget_ops = array('classname' => 'OqueWidget', 'description' => 'O que é? Gabinete Digital. Documento unico O que é?' );
$this->WP_Widget('OqueWidget', 'Gabinete Digital - O que é? Único', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'post_id' => '', 'colunas' => '3', 'css_class' => '' ) );
$titulo = $instance['titulo'];
$post_id = $instance['post_id'];
$colunas = $instance['colunas'];
$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('post_id'); ?>">ID: <input class="widefat" id="<?php echo $this->get_field_id('post_id'); ?>" name="<?php echo $this->get_field_name('post_id'); ?>" type="text" value="<?php echo attribute_escape($post_id); ?>" /></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('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['post_id'] = $new_instance['post_id'];
$instance['colunas'] = $new_instance['colunas'];
$instance['css_class'] = $new_instance['css_class'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$args_query_post = '';
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_titulo', $instance['titulo']);
$post_id = $instance['post_id'];
$colunas = $instance['colunas'];
$custom_post = 'oquegd_oque';
echo "<li class='span".$instance['colunas']."'><div class='thumbnail oque_lista ".$instance['css_class']."'>";
echo $before_title . $titulo . $after_title;;
if (!empty($post_id))
$args_query_post = $args_query_post . "p=" . $post_id;
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;
}
query_posts($args_query_post);
if (have_posts()) :
echo "<ul>";
while (have_posts()) : the_post();
echo "<li><a href='".get_permalink()."'>".get_the_title()."</a><br>" . get_the_excerpt(). "</li>";
endwhile;
echo "</ul>";
endif;
wp_reset_query();
echo "</div></li>";
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("OqueWidget");') );
?>