-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget-recent-apps.php
96 lines (81 loc) · 1.97 KB
/
widget-recent-apps.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
<?php
class iFavorites_Recent_Apps_Widget extends WP_Widget {
function __construct()
{
parent::__construct(
'recent_apps_widget',
__("Recent Apps", 'ifavorites'),
array(
'description' => __("The most recent apps on your site", 'ifavorites'),
)
);
}
function widget($args, $instance)
{
extract($args);
echo $before_widget;
$title = apply_filters('widget_title', $instance['title']);
if (empty($title)) $title = __("Recent Apps", 'ifavorites');
if ($title) echo $before_title.$title.$after_title;
$apps = new WP_Query(array(
'post_type' => 'app',
'posts_per_page' => $instance['number'],
'post_status' => 'publish',
'ignore_sticky_posts' => true,
));
?>
<ul>
<?php while ($apps->have_posts()): $apps->the_post(); ?>
<li>
<a
href="<?php the_permalink(); ?>"
title="<?=esc_attr(get_the_title())?>"
>
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php
echo $after_widget;
wp_reset_postdata();
}
function update($new_instance, $old_instance)
{
return array_merge($old_instance, array(
'title' => strip_tags($new_instance['title']),
'number' => intval($new_instance['number']),
));
}
function form($instance)
{
$title = isset($instance['title']) ? $instance['title'] : '';
$number = isset($instance['number']) ? $instance['number'] : 5;
?>
<p>
<label for="<?=$this->get_field_id('title')?>">
<?=__("Title:", 'ifavorites')?>
</label>
<input
type="text"
class="widefat"
id="<?=$this->get_field_id('title')?>"
name="<?=esc_attr($this->get_field_name('title'))?>"
value="<?=esc_attr($title)?>"
/>
</p>
<p>
<label for="<?=$this->get_field_id('number')?>">
<?=__("Number of apps to show:", 'ifavorites')?>
</label>
<input
type="text"
size="3"
id="<?=$this->get_field_id('number')?>"
name="<?=esc_attr($this->get_field_name('number'))?>"
value="<?=esc_attr($number)?>"
/>
</p>
<?php
}
}