-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-mission-trip.php
125 lines (103 loc) · 4.11 KB
/
single-mission-trip.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
<?php
/**
* Single mission trip.
*
* @package Dkjensen\JesusFilmProject
* @link https://dkjensen.com
* @author David Jensen
* @copyright Copyright © 2021 David Jensen
* @license GPL-3.0
*/
namespace Dkjensen\JesusFilmProject;
\remove_all_actions( 'genesis_entry_footer' );
\remove_action( 'genesis_after_content_sidebar_wrap', 'genesis_posts_nav' );
\remove_action( 'genesis_after_content_sidebar_wrap', 'genesis_adjacent_entry_nav' );
\add_action( 'genesis_hero_section', __NAMESPACE__ . '\single_mission_trip_hero_prefix', 8 );
/**
* Before hero title
*
* @return void
*/
function single_mission_trip_hero_prefix() {
printf( '<h5><a href="%s">%s /</a></h5>', \esc_url( \get_permalink( \get_page_by_path( '/partners/mission-trips/' ) ) ), esc_html__( 'GO', 'jesus-film-project' ) );
}
\add_action( 'genesis_hero_after_title', __NAMESPACE__ . '\single_mission_trip_hero_suffix' );
/**
* After hero title
*
* @return void
*/
function single_mission_trip_hero_suffix() {
$start_date = \DateTime::createFromFormat( 'Ymd', \get_post_meta( \get_the_ID(), 'date_start', true ) );
$end_date = \DateTime::createFromFormat( 'Ymd', \get_post_meta( \get_the_ID(), 'date_end', true ) );
if ( $start_date && $end_date ) {
printf( '<h5>%s - %s</h5>', \esc_html( $start_date->format( 'F j, Y' ) ), \esc_html( $end_date->format( 'F j, Y' ) ) );
} elseif ( $start_date && ! $end_date ) {
printf( '<h5>%s %s</h5>', \esc_html__( 'Starting', 'jesus-film-project' ), \esc_html( $start_date->format( 'F j, Y' ) ) );
} elseif ( ! $start_date && $end_date ) {
printf( '<h5>%s %s</h5>', \esc_html__( 'Thru', 'jesus-film-project' ), \esc_html( $end_date->format( 'F j, Y' ) ) );
}
}
\add_action( 'genesis_entry_content', __NAMESPACE__ . '\single_mission_trip_details', 5 );
/**
* Output the mission trip specs.
*
* @return void
*/
function single_mission_trip_details() {
$mission_trip_meta = \get_post_meta( \get_the_ID() );
$details = '<dl class="mission-trip-specs">';
foreach ( $mission_trip_meta as $key => $meta ) {
switch ( $key ) {
case 'region':
$regions = \get_the_terms( \get_the_ID(), 'region' );
if ( $regions && ! \is_wp_error( $regions ) ) {
$details .= sprintf( "<dt data-meta=\"%s\">%s</dt>\n<dd>%s</dd>\n", \esc_attr( $key ), esc_html__( 'Region', 'jesus-film-project' ), esc_html( implode( ', ', \wp_list_pluck( $regions, 'name' ) ) ) );
}
break;
case 'strategies':
$strategies = wp_get_post_terms( \get_the_ID(), 'strategy', array( 'hide_empty' => false ) );
if ( $strategies && ! \is_wp_error( $strategies ) ) {
$strategies = array_map(
function( $strategy ) {
return sprintf( '<a href="%s">%s</a>', get_term_link( $strategy->term_id, 'strategy' ), esc_html( $strategy->name ) );
},
$strategies
);
$details .= sprintf( "<dt data-meta=\"%s\">%s</dt>\n<dd>%s</dd>\n", \esc_attr( $key ), esc_html__( 'Strategies', 'jesus-film-project' ), "<ul>\n" . implode( ', ', $strategies ) . "\n</ul>" );
}
break;
case 'location':
$details .= sprintf( "<dt data-meta=\"%s\">%s</dt>\n<dd>%s</dd>\n", \esc_attr( $key ), esc_html__( 'Location', 'jesus-film-project' ), esc_html( current( $meta ) ) );
break;
case 'cost':
$details .= sprintf( "<dt data-meta=\"%s\">%s</dt>\n<dd>%s</dd>\n", \esc_attr( $key ), esc_html__( 'Cost', 'jesus-film-project' ), esc_html( current( $meta ) ) );
break;
case 'status':
$details .= sprintf( "<dt data-meta=\"%1\$s\">%2\$s</dt>\n<dd data-status=\"%3\$s\">%3\$s</dd>\n", \esc_attr( $key ), esc_html__( 'Status', 'jesus-film-project' ), esc_html( ucfirst( current( $meta ) ) ) );
break;
}
}
$details .= '</dl>' . "\n";
$details .= do_shortcode( '[share_post]' );
\genesis_markup(
array(
'open' => '<div %s>',
'close' => '</div>',
'content' => $details,
'context' => 'mission-trip-details',
)
);
}
\add_filter( 'genesis_site_layout', __NAMESPACE__ . '\single_mission_trip_site_layout' );
/**
* Site layout.
*
* @param string $layout Default layout.
*
* @return string
*/
function single_mission_trip_site_layout( $layout ) {
return 'content-sidebar';
}
\genesis();