-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
187 lines (174 loc) · 6.07 KB
/
index.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
187
<?php
/*
Plugin Name: Schwingen Agenda
Plugin URI: http://www.impres-sign.com/
Description: Events-Register (Agenda) mit Download von Rangliste. In unserem Falle wird dies fuer den schweizer Schwingsport gebraucht, um alle Schwingfeste und Events zu erfassen.
Version: 1.0
Author: Marc Juchli
Author URI: http://www.impres-sign.com/
License: GPL
Stable Tag: 1.0
*/
?>
<?php
//Plugin-init
add_action('init', 'agenda');
function agenda() {
$labels = array(
'name' => _x('Agenda', 'post type general name'),
'singular_name' => _x('Agenda', 'post type singular name'),
'add_new' => _x('Add New', 'portfolio item'),
'add_new_item' => __('Add New Portfolio Item'),
'edit_item' => __('Edit Portfolio Item'),
'new_item' => __('New Portfolio Item'),
'view_item' => __('View Portfolio Item'),
'search_items' => __('Search Portfolio'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => true,
'rewrite' => array('slug' => 'agenda'),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 4,
'supports' => array('')
);
register_post_type( 'agenda' , $args );
}
//Einteilung von Verwaltungsmaske
add_action("admin_init", "agenda_init");
function agenda_init(){
add_meta_box("agenda_dates_meta", "Datum", "agenda_dates_meta", "agenda", "side", "low");
add_meta_box("agenda_credits_meta", "Angaben zum Schwingfest", "agenda_credits_meta", "agenda", "normal", "low");
add_meta_box("agenda_upload_meta", "Rangliste", "agenda_upload_meta", "agenda", "normal", "low");
}
//Input Felder credits_meta (Angaben zum Schwingfest)
function agenda_credits_meta(){
global $post;
$custom = get_post_custom($post->ID);
$description = $custom["description"][0];
$place = $custom["place"][0];
?>
<label>Bezeichnung:</label><br />
<input size="50" name="description" value="<?php echo $description; ?>" /><br />
<label>Ortschaft:</label><br />
<input size="50" name="place" value="<?php echo $place; ?>" />
<?php
}
//Input Felder upload_meta (Rangliste)
function agenda_upload_meta(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["link"][0];
?>
<label>Link:</label><br />
<input size="50" name="link" value="<?php echo $link; ?>" /><br />
<?php
}
//Input Felder dates_meta (Datum)
function agenda_dates_meta(){
global $post;
$custom = get_post_custom($post->ID);
//$dateFromD = $custom["dateFromD"][0];
//$dateFromM = $custom["dateFromM"][0];
//$dateFromY = $custom["dateFromY"][0];
$dateFromD = date("d", $custom["dateFrom"][0]);
$dateFromM = date("m", $custom["dateFrom"][0]);
$dateFromY = date("Y", $custom["dateFrom"][0]);
//$dateTo = $custom["dateTo"][0];
?>
<label>Beginn (D/M/Y):</label><br />
<input size="2" name="dateFromD" value="<?php echo $dateFromD; ?>" />
<input size="2" name="dateFromM" value="<?php echo $dateFromM; ?>" />
<input size="5" name="dateFromY" value="<?php echo $dateFromY; ?>" /><br />
<!-- <label>Ende:</label><br />
<input size="25" name="dateTo" value="<?php //echo $dateTo; ?>" /><br /> -->
<?php
}
//Zuordung fuer Update
function agenda_save_details(){
global $post;
global $wpdb;
$dateFrom = mktime(0, 0, 0, $_POST['dateFromM'], $_POST['dateFromD'], $_POST['dateFromY']);
update_post_meta($post->ID, "description", $_POST["description"]);
update_post_meta($post->ID, "place", $_POST["place"]);
update_post_meta($post->ID, "link", $_POST["link"]);
update_post_meta($post->ID, "dateFrom", $dateFrom);
//update_post_meta($post->ID, "dateTo", $_POST["dateTo"]);
}
add_action('save_post', 'agenda_save_details');
// Formatierung der Tabelle im backend
add_filter('manage_edit-agenda_columns', 'add_new_agenda_columns');
function add_new_agenda_columns($gallery_columns) {
$new_columns['cb'] = '<input type="checkbox" />';
$new_columns['id'] = __('ID');
$new_columns['dateFrom'] = __('Datum');
$new_columns['description'] = __('Schwingfest');
$new_columns['place'] = __('Ortschaft');
$new_columns['link'] = _x('Rangliste');
return $new_columns;
}
// Formatierung der Tabelle im backend
add_action('manage_agenda_posts_custom_column', 'manage_agenda_columns', 10, 2);
function manage_agenda_columns($column_name, $id) {
global $wpdb;
switch ($column_name) {
case 'id':
echo $id;
break;
case 'dateFrom':
echo "<a href=\"post.php?post=".$id."&action=edit\">".date("d.m.Y", get_post_meta($id, 'dateFrom', true))."</a>";
break;
case 'description':
echo "<a href=\"post.php?post=".$id."&action=edit\">".get_post_meta($id, 'description', true)."</a>";
break;
case 'place':
echo "<a href=\"post.php?post=".$id."&action=edit\">".get_post_meta($id, 'place', true)."</a>";
break;
case 'link':
echo "<a href=\"post.php?post=".$id."&action=edit\">".get_post_meta($id, 'link', true)."</a>";
break;
default:
break;
} // end switch
}
// -- BACKEND nun abgeschlossen --
//Liste fuer Aufruf im Frontend
function agenda_frontend_list() {
global $post;
rewind_posts();
// Create a new WP_Query() object
$wpcust = new WP_Query(
array(
'post_type' => array('agenda'),
'showposts' => '500', // or 10 etc. however many you want
'orderby' => 'dateFrom', 'order' => 'ASC'
)
);
//print_r($wpcust);
if ( $wpcust->have_posts() ) : while( $wpcust->have_posts() ) : $wpcust->the_post();
$description = get_post_meta($post->ID, 'description', true);
$place = get_post_meta($post->ID, 'place', true);
$link = get_post_meta($post->ID, 'link', true);
$dateFrom = get_post_meta($post->ID, 'dateFrom', true);
$dateFrom = date("d.m.Y", $dateFrom)
?>
<ul class="cf">
<li class="left"><?php echo $dateFrom; ?></li>
<li class="left" style="width: 334px"><?php echo $description; ?></li>
<li class="left" style="width: 125px"><?php echo $place; ?></li>
<li class="left"><?php if($link != ""){ ?><a href="<?php echo $link; ?>">Rangliste</a><?php } ?></li>
</ul>
<?php
endwhile; endif;
wp_reset_query(); // reset the Loop
}
?>