Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. add_action( 'genesis_before_post_content', 'trailer_meta_content' );
  2. /**
  3.  * Show trailer meta content.
  4.  *
  5.  * @since 1.0
  6.  * @author Gary Jones
  7.  *
  8.  * @global stdClass $post WP Post object
  9.  * @global string $prefix
  10.  * @return null Returns null if post type is not "trailer"
  11.  */
  12. function trailer_meta_content() {
  13.  
  14.     global $post, $prefix;
  15.  
  16.     // If not our trailer post type, bail out
  17.     if ( 'trailer' != get_post_type() )
  18.         return;
  19.  
  20.     // Set up grabbing the attributes and their outputs.
  21.     // You should wrap each string in __() for translations.
  22.     // Also check out genesis_get_custom_field().
  23.     $attributes = apply_filters( 'trailer_attributes', array(
  24.         array( get_custom_field( $prefix . 'inventory_number' ), 'Inventory Number: %1$s<br /><a href="/contact?inventory=%1$s" title="contact us about this equipment">Contact us about this equipment</a>' ),
  25.         array( get_the_term_list( $post->ID, 'status', 'New/Used: ', ' ', '' ), '%s' ),
  26.         array( get_the_term_list( $post->ID, 'classification', 'Classification: ', ' ', '' ), '%s' ),
  27.         array( get_custom_field( $prefix . 'year' ), 'Year: %s' ),
  28.         array( get_the_term_list( $post->ID, 'manufacturer', 'Manufacturer: ', ' ', '' ), '%s' ),
  29.         array( get_the_term_list( $post->ID, 'type', 'Type: ', ' ', '' ), '%s' ),
  30.         array( get_custom_field( $prefix . 'compartments' ), 'Compartments: %s' ),
  31.         array( get_the_term_list( $post->ID, 'material', 'Material: ', ' ', '' ), '%s' ),
  32.         array( get_custom_field( $prefix . 'location' ), 'Location: %s' ),
  33.         array( get_custom_field( $prefix . 'capacity' ), 'Capacity: %s' ),
  34.         array( get_custom_field( $prefix . 'code' ), 'Code: %s' ),
  35.     ), $post, $prefix );
  36.  
  37.     // Loop through the attributes, assigning to an array
  38.     foreach ( $attributes as $attribute ) {
  39.         if ( $value = $attribute[0] )
  40.             $output[] = esc_html( sprintf( $attribute[1], $value ) );
  41.     }
  42.  
  43.     // Grab the first attachment if there is one
  44.     $args = array(
  45.         'post_type'      => 'attachment',
  46.         'post_mime_type' => array( 'application/doc', 'application/pdf' ),
  47.         'numberposts'    => 1,
  48.         'post_status'    => null,
  49.         'post_parent'    => $post->ID
  50.     );
  51.     $attachments = get_posts( $args );
  52.  
  53.     // Add the first attachment to our output array
  54.     foreach ( $attachments as $attachment ) {
  55.         $output[] = '<a href="' . esc_url( wp_get_attachment_url( $attachment->ID ) ) . '">Download Spec Sheet</a>';
  56.     }
  57.  
  58.     // Echo the attributes, each on a new line, and wrapped in a div if there is anything to output.
  59.     if ( $output = implode( '<br />', $output ) )
  60.         echo '<div id="trailer-specifications">' . $output . '</div>';
  61.  
  62.     if ( has_post_thumbnail() )
  63.         printf( '<a href="%1$s" title="%2$s" rel="shadowbox">%3$s</a>',
  64.             esc_url( wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' ) ),
  65.             esc_attr( the_title_attribute( 'echo=0' ) ),
  66.             esc_html( the_post_thumbnail( 'thumbnail' ) )
  67.         );
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement