-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-clippinggd-widget.php
186 lines (150 loc) · 7.47 KB
/
wp-clippinggd-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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/********************************************
* WIDGET PARA MONTAR UMA LISTA DE CLIPPING
********************************************/
class ListaClippingGDWidget extends WP_Widget
{
function ListaClippingGDWidget()
{
$widget_ops = array('classname' => 'ListaClippingGDWidget', 'description' => 'Lista de Clipping do Gabinete Digital, custom post type.' );
$this->WP_Widget('ListaClippingGDWidget', 'Gabinete Digital - Clipping Lista', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'colunas' => '3', 'qtd' => '1', '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);
global $wpdb;
$args_query_post = '';
$txtreturn = '';
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_titulo', $instance['titulo']);
$colunas = $instance['colunas'];
$qtd = $instance['qtd'];
$custom_post = 'clippinggd_clipping';
if (empty($qtd))
$qtd = 4;
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;
}
$args_query_post .= "&posts_per_page=-1"; //para vir todos os posts
query_posts($args_query_post);
$txtreturn .= "<div class='clipping ".$instance['css_class']."'>";
if (!empty($titulo))
$txtreturn .= "<h3>".$titulo."</h3>";
$txtreturn .= "<input name='clipping-perpage' type='hidden' id='clipping-perpage' value='$qtd' />";
$txtreturn .= "<div id='clipping-itemsclipping'>";
if (have_posts()) :
while (have_posts()) : the_post();
$fonte = get_post_meta(get_the_ID(),'wp_clippinggd_fonte', true);
$anexo = get_post_meta(get_the_ID(),'wp_clippinggd_anexo', true);
$url = get_post_meta(get_the_ID(),'wp_clippinggd_url', true);
if (!empty($anexo)){
$url = wp_get_attachment_url( $anexo );
}
$txtreturn .= "<blockquote class='pull-right'>";
$txtreturn .= "<p class='Lead'>".get_the_title()."</p>";
$txtreturn .= "<small><a href='".$url."'>".$fonte."</a></small>";
$txtreturn .= "</blockquote>";
endwhile;
endif;
wp_reset_query();
$txtreturn .= "</div>";
$txtreturn .= "</div>";
echo $txtreturn;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("ListaClippingGDWidget");') );
/******************************************
*WIDGET PARA MONTAGEM DE UM CLIPPING EM ESPECIFICO PELO POST_ID
*****************************************/
class ClippingGDWidget extends WP_Widget
{
function ClippingGDWidget()
{
$widget_ops = array('classname' => 'ClippingGDWidget', 'description' => 'Clipping do Gabinete Digital, custom post type.' );
$this->WP_Widget('ClippingGDWidget', 'Gabinete Digital - Clipping Único', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'titulo' => '', 'colunas' => '3', 'post_id' => '', 'css_class' => '' ) );
$titulo = $instance['titulo'];
$colunas = $instance['colunas'];
$post_id = $instance['post_id'];
$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 do post: <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['colunas'] = $new_instance['colunas'];
$instance['post_id'] = $new_instance['post_id'];
$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']."'><div class='thumbnail clipping_unico ".$instance['css_class']."'>";
$titulo = empty($instance['titulo']) ? ' ' : apply_filters('widget_titulo', $instance['titulo']);
$colunas = $instance['colunas'];
$post_id = $instance['post_id'];
$custom_post = 'clippinggd_clipping';
if (!empty($titulo))
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();
$fonte = get_post_meta(get_the_ID(),'wp_clippinggd_fonte', true);
$url = get_post_meta(get_the_ID(),'wp_clippinggd_url', true);
echo "<li><a href='".$url."' target='_blank'>".get_the_title()."</a><br>Fonte: " . $fonte . "</li>";
endwhile;
echo "</ul>";
endif;
wp_reset_query();
echo "</div></li>";
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("ClippingGDWidget");') );
?>