Skip to content

Commit

Permalink
Support for sticky productions.
Browse files Browse the repository at this point in the history
- Sticky productions are added to the _bottom_ of production listings.
  • Loading branch information
slimndap committed Jan 14, 2014
1 parent 6ed3a97 commit 3be0375
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
32 changes: 29 additions & 3 deletions functions/wpt_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ function admin_menu() {

function add_meta_boxes() {
add_meta_box(
'wp_theatre_sticky',
__('Display','wp_theatre'),
array($this,'meta_box_sticky'),
WPT_Production::post_type()->name,
'side'
);
add_meta_box(
'wp_theatre_events',
WPT_Event::post_type()->labels->name,
array($this,'meta_box_events'),
Expand Down Expand Up @@ -76,6 +83,19 @@ function add_meta_boxes() {
);
}

function meta_box_sticky($production) {
echo '<label>';

echo '<input type="checkbox" name="sticky"';
if (is_sticky()) {
echo ' checked="checked"';
}
echo ' />';
echo __('Stick this production to all listings.','wp_theatre');

echo '</label>';
}

function meta_box_events($production) {
$production = new WPT_Production(get_the_id());

Expand Down Expand Up @@ -253,9 +273,9 @@ function meta_box_seasons($production) {
);

$seasons = get_posts($args);
echo '<select name="'.WPT_Season::post_type_name.'">';
echo '<option></option>';
if (count($seasons)>0) {
echo '<select name="'.WPT_Season::post_type_name.'">';
echo '<option></option>';
foreach ($seasons as $season) {
echo '<option value="'.$season->ID.'"';
if (get_post_meta($production->ID,WPT_Season::post_type_name,true)==$season->ID) {
Expand All @@ -265,9 +285,9 @@ function meta_box_seasons($production) {
echo $season->post_title;
echo '</option>';
}
echo '</select>';

}
echo '</select>';

}

Expand Down Expand Up @@ -367,9 +387,15 @@ function save_production( $post_id ) {

// Sanitize the user input.
$season = sanitize_text_field( $_POST[WPT_Season::post_type_name] );

$sticky = '';
if (isset($_POST['sticky'])) {
$sticky = sanitize_text_field( $_POST['sticky'] );
}

// Update the meta field.
update_post_meta( $post_id, WPT_Season::post_type_name, $season );
update_post_meta( $post_id, 'sticky', $sticky );


}
Expand Down
4 changes: 2 additions & 2 deletions functions/wpt_event.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ function datetime() {

function date() {
if (!isset($this->date)) {
$this->date = date(get_option('date_format'),$this->datetime());
$this->date = date_i18n(get_option('date_format'),$this->datetime());
}
return $this->date;
}

function time() {
if (!isset($this->time)) {
$this->time = date(get_option('time_format'),$this->datetime());
$this->time = date_i18n(get_option('time_format'),$this->datetime());
}
return $this->time;
}
Expand Down
15 changes: 11 additions & 4 deletions theatre.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,24 @@ function get_productions($PostClass = false) {

$posts = get_posts($args);

$productions = array();
$upcoming = array();
$stickies = array();
for ($i=0;$i<count($posts);$i++) {
$production = new WPT_Production($posts[$i], $PostClass);
if ($production->is_upcoming()) {
$events = $production->events();
$productions[$events[0]->datetime()] = $production;
$upcoming[$events[0]->datetime()] = $production;
} elseif (is_sticky($production->ID)) {
$stickies[] = $production;
}
}

ksort($productions);
return array_values($productions);
ksort($upcoming);
$upcoming = array_values($upcoming);

$productions = array_merge($upcoming,$stickies);

return $productions;
}

function get_events($PostClass = false) {
Expand Down

0 comments on commit 3be0375

Please sign in to comment.