SHOW:
|
|
- or go back to the newest paste.
| 1 | - | remove_action( 'genesis_post_content', 'custom_excerpt' ); |
| 1 | + | /** Hotel Excerpts |
| 2 | - | add_action( 'genesis_post_content', 'custom_excerpt' ); |
| 2 | + | * |
| 3 | - | function custom_excerpt() {
|
| 3 | + | * Display an excerpt of address |
| 4 | * on Hotel CPTS using ACF. | |
| 5 | * | |
| 6 | * @author Angie Meeker | |
| 7 | - | $address_data = array( |
| 7 | + | * @uses Advanced Custom Fields |
| 8 | */ | |
| 9 | remove_action( 'genesis_post_content', 'hotel_excerpt' ); | |
| 10 | add_action( 'genesis_post_content', 'hotel_excerpt' ); | |
| 11 | function hotel_excerpt() {
| |
| 12 | // Return if CPT Hotels | |
| 13 | if ( is_post_type_archive( 'hotels' ) ) | |
| 14 | ||
| 15 | // Store the address data | |
| 16 | $hotel_excerpt_data = array( | |
| 17 | - | if( $address_data ) {
|
| 17 | + | |
| 18 | - | echo '<div class="details">Details</div>'; |
| 18 | + | |
| 19 | - | echo '<div class="location-wrap one-half first">'; |
| 19 | + | |
| 20 | - | if ( $address_data['address_1'] ) {
|
| 20 | + | |
| 21 | - | echo '<div class="location">' . esc_attr( $address_data['address_1'] ) . '</div>'; |
| 21 | + | |
| 22 | 'zip' => get_field( 'zip' ), | |
| 23 | - | if ( $address_data['address_2'] ) {
|
| 23 | + | 'phone' => get_field( 'phone' ), |
| 24 | - | echo '<div class="location">' . esc_attr( $address_data['address_2'] ) . '</div>'; |
| 24 | + | 'website' => get_field( 'website' ), |
| 25 | ); | |
| 26 | - | if ( $address_data['po_box'] ) {
|
| 26 | + | |
| 27 | - | echo '<div class="location">' . esc_attr( $address_data['po_box'] ) . '</div>'; |
| 27 | + | |
| 28 | if( $hotel_excerpt_data ) {
| |
| 29 | - | if ( $address_data['city'] ) {
|
| 29 | + | echo '<div class="hotelexcerpt">'; |
| 30 | - | echo '<span>' . esc_attr( $address_data['city'] ) . '</span>'; |
| 30 | + | if ( $hotel_excerpt_data['address_1'] ) {
|
| 31 | echo '<div class="location">' . esc_attr( $hotel_excerpt_data['address_1'] ) . '</div>'; | |
| 32 | - | if ( $address_data['state'] ) {
|
| 32 | + | |
| 33 | - | echo '<span>, ' . esc_attr( $address_data['state'] ) . '</span>'; |
| 33 | + | if ( $hotel_excerpt_data['address_2'] ) {
|
| 34 | echo '<div class="location">' . esc_attr( $hotel_excerpt_data['address_2'] ) . '</div>'; | |
| 35 | - | if ( $address_data['zip'] ) {
|
| 35 | + | |
| 36 | - | echo '<span> ' . esc_attr( $address_data['zip'] ) . '</span>'; |
| 36 | + | if ( $hotel_excerpt_data['po_box'] ) {
|
| 37 | echo '<div class="location">' . esc_attr( $hotel_excerpt_data['po_box'] ) . '</div>'; | |
| 38 | - | echo '</div>'; |
| 38 | + | |
| 39 | if ( $hotel_excerpt_data['city'] ) {
| |
| 40 | - | if ( '' != $address_data ) {
|
| 40 | + | echo '<span>' . esc_attr( $hotel_excerpt_data['city'] ) . '</span>'; |
| 41 | - | $address_data = strip_shortcodes( $text ); |
| 41 | + | |
| 42 | - | $address_data = apply_filters('the_content', $text);
|
| 42 | + | if ( $hotel_excerpt_data['state'] ) {
|
| 43 | echo '<span>, ' . esc_attr( $hotel_excerpt_data['state'] ) . '</span>'; | |
| 44 | - | $address_data = strip_tags($text, $allowed_tags); |
| 44 | + | |
| 45 | - | $address_data = str_replace(']]>', ']]>', $text);
|
| 45 | + | if ( $hotel_excerpt_data['zip'] ) {
|
| 46 | - | $excerpt_length = 40; // 20 words |
| 46 | + | echo '<span> ' . esc_attr( $hotel_excerpt_data['zip'] ) . '</span>'; |
| 47 | - | $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
|
| 47 | + | |
| 48 | - | $address_data = wp_trim_words( $text, $excerpt_length, $excerpt_more ); |
| 48 | + | if ( $hotel_excerpt_data['phone'] ) {
|
| 49 | echo '<div class="location">' . esc_attr( $hotel_excerpt_data['phone'] ) . '</div>'; | |
| 50 | } | |
| 51 | if ( $hotel_excerpt_data['website'] ) {
| |
| 52 | echo '<div class="location"><a href="' . esc_url( $hotel_excerpt_data['website'] ) . '">Visit Our Website</a></div>'; | |
| 53 | } | |
| 54 | if ( $hotel_excerpt_data['email'] ) {
| |
| 55 | echo '<div class="location"><a href="mailto:' . esc_attr( $hotel_excerpt_data['email'] ) . '">Email</a></div>'; | |
| 56 | } | |
| 57 | echo '</div>'; | |
| 58 | } | |
| 59 | if ( '' != $hotel_excerpt_data ) {
| |
| 60 | $hotel_excerpt_data = strip_shortcodes( $text ); | |
| 61 | $hotel_excerpt_data = apply_filters('the_content', $text);
| |
| 62 | $allowed_tags = '<p>,<a>,<em>,<strong>,<img>'; | |
| 63 | $hotel_excerpt_data = strip_tags($text, $allowed_tags); | |
| 64 | $hotel_excerpt_data = str_replace(']]>', ']]>', $text);
| |
| 65 | $excerpt_length = 0; // 20 words | |
| 66 | ||
| 67 | $hotel_excerpt_data = wp_trim_words( $text, $excerpt_length, $excerpt_more ); | |
| 68 | } | |
| 69 | return apply_filters('the_excerpt', $text);
| |
| 70 | } |