Advertisement
marjwyatt

song_single_genesis

Apr 19th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.89 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Single Post Template: Songs Single
  4.  */
  5. //Pastebin Reference link: Coming Soon
  6. //Ref post links:
  7. // http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
  8. // http://wordpress.org/support/topic/auto-use-first-image-in-post-as-featured-image
  9. // uses http://www.tipsandtricks-hq.com/wordpress-audio-music-player-plugin-4556
  10.  
  11. function song_first_image( $postid ) {
  12.     // not used in theme but kept on script just in case global function fails
  13.     $args = array(
  14.         'numberposts' => 1,
  15.         'order' => 'ASC',
  16.         'post_mime_type' => 'image',
  17.         'post_parent' => $postid,
  18.         'post_status' => null,
  19.         'post_type' => 'attachment',
  20.     );
  21.  
  22.     $attachments = get_children( $args );
  23.  
  24.     if ( $attachments ) {
  25.         foreach ( $attachments as $attachment ) {
  26.             $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'Song_Single_Thumb' )  ? wp_get_attachment_image_src( $attachment->ID, 'Song_Single_Thumb' ) : wp_get_attachment_image_src( $attachment->ID, 'full' );
  27.             echo '<img src="' . $image_attributes[0] . '" width="' . $image_attributes[1] . '" height="' . $image_attributes[2] .'">';
  28.         }
  29.     }
  30. }
  31.  
  32. function song_single_image() {
  33.     if ( is_singular() && has_post_thumbnail() ) {
  34.         $img = genesis_get_image( array( 'format' => 'html', 'size' => the_post_thumbnail( 'Song_Single_Thumb' ), 'attr' => array( 'class' => 'aligncenter Song_Single_Thumb' ) ) );
  35.     }
  36. }
  37.  
  38. /** Customize the post info */
  39. add_filter( 'genesis_post_info', 'song_single_post_info' );
  40. function song_single_post_info($post_info) {
  41.     //$post_info = '[post_date format="F j, Y"] by [post_author_posts_link before="<b>" after="</b>"]';
  42.     $post_info = '[post_date format="F j, Y"]';
  43.     return $post_info;
  44. }
  45.  
  46. // Force content-sidebar layout setting
  47. add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
  48.  
  49. remove_action( 'genesis_loop', 'genesis_do_loop' );
  50. add_action( 'genesis_loop', 'songs_single' );
  51. function songs_single() {
  52. $query_one = new WP_Query ( array( 'post_type' => 'song', 'posts_per_page' => '1' ) );
  53. ?>
  54. <?php genesis_before_post(); ?>
  55. <?php genesis_before_post_title();
  56. echo '<div itemscope itemtype ="http://schema.org/MusicRecording" class="songs">'; // echo out schema item type
  57.     echo '<h1 itemprop="name">'; // echo out schema property
  58.     echo ( get_the_title() ); // using post title as schema item property
  59.     echo '</h1>'; ?>
  60. <?php genesis_after_post_title(); ?>
  61. <!--<?php song_single_post_info($post_info); ?>-->
  62. <?php genesis_before_post_content(); ?>
  63. <?php if ($query_one->have_posts()) : // custom query for primary post content
  64.     $postid = get_the_id();
  65.     $cats = get_the_category();
  66.     $cat = $cats[0];
  67.     $cat_id = $cat->cat_ID;
  68.     $cat_name = $cat->name;
  69.     $cat_slug = $cat->slug;
  70.     $artist = get_the_author();
  71.     $artistPostLink = the_author_posts_link();
  72.     $artistNew = get_the_author_meta('display_name',get_queried_object()->post_author);
  73.     $artistID = get_the_author_meta('ID',get_queried_object()->post_author);
  74.     //$another_artist = get_the_author_meta('display_name');
  75.     //Ref link: http://codex.wordpress.org/Function_Reference/the_author_meta
  76.     //$songThumb = song_single_image();
  77.     $i=0; // counter
  78.     while ($query_one->have_posts()) : the_post(); $do_not_duplicate = $post->ID; ?>
  79.     <?php if ($i == 0) {
  80.         $artistPostLink = get_the_author_link();
  81.         $artistPosts = get_the_author_posts(); ?>
  82.         <div class="songs">
  83.             <div itemprop="thumbnail" class="one-third first"><?php song_single_image(); ?></div>
  84.             <div class="one-third second">
  85.             <?php if ( get_post_meta($postid, '_songs_songFile', true) ) : // verify that custom data exists before output
  86.                 $songFile = ( get_post_meta($postid, "_songs_songFile", true) );
  87.                 echo '<span class="hrlabel">Listen to ' . get_the_title() . ' :</span>'; // section label
  88.                 //echo '<p class="audio">'; // echo out schema property
  89.                 echo '<div itemprop="audio" class="audio">';
  90.                 echo do_shortcode ( '[sc_embed_player fileurl="' . $songFile .'"]' );
  91.                 echo '</div>';
  92.             endif; ?>
  93.             <?php if ( get_post_meta($postid, '_songs_songArtist', true) ) : // verify that custom data exists before output
  94.                 echo '<p itemprop="byArtist" class="byArtist">'; // echo out schema property
  95.                 echo '<span class="hrlabel">Artist:&nbsp;&nbsp;</span>'; // section label
  96.                 echo ( get_post_meta($postid, "_songs_songArtist", true) ); // echo custom field
  97.                 echo '</p>';
  98.             endif; ?>
  99.             <?php if ( get_post_meta($postid, '_songs_songAlbum', true) ) : // verify that custom data exists before output
  100.                 echo '<p itemprop="inAlbum" class="inAlbum">'; // echo out schema property
  101.                 echo '<span class="hrlabel">From Album:&nbsp;&nbsp;</span>'; // section label
  102.                 echo ( get_post_meta($postid, "_songs_songAlbum", true) ); // echo custom field
  103.                 echo '</p>';
  104.             endif; ?>
  105.             </div>
  106.             <div class="one-third">
  107.             <?php if ( get_post_meta($postid, '_songs_songContributor', true) ) : // verify that custom data exists before output
  108.                 echo '<div class="contributor"><span class="hrlabel">Other Contributors:</span>'; // Echo out the div class & title
  109.                 echo '<span itemprop="contributor">'; // Echo Schema property
  110.                 echo wpautop( get_post_meta( $postid, "_songs_songContributor", true ) ); // Echo out other contributors entry
  111.                 echo '</span></div>'; //Close up itemprop span & div class
  112.             endif; ?>
  113.             </div>
  114.             <?php echo '<div class="description" itemprop="description">'; // echo out schema property
  115.                 echo ( wpautop (the_content()) ); // using post content as song description, preserve paragraphs with wpautop
  116.                 echo '</div>';
  117.              ?>
  118.         </div>
  119.         <?php $i++; ?>
  120.         </div><!-- end .entry-content -->
  121.  
  122.     <?php }; ?>
  123.     <?php rewind_posts(); ?>
  124.     <?php if ($i == 1) { ?>
  125.             <div id="accordion-single">
  126.                 <?php $shrt_cd = "[accordion title='All music from " . $artistNew . "']";
  127.                     $query_two = new WP_Query ( array ( 'post_type' => 'song', 'author' => $artistID, 'posts_per_page' => '-1' ) );
  128.                     $shrt_cd .= '<ul class="accordion-single-list">';
  129.                     if ($query_two->have_posts()) :
  130.                     while ($query_two->have_posts()) : $query_two->the_post();
  131.                     if( !$post->ID == $do_not_duplicate ) continue;
  132.                         $shrt_cd .= '<li><a href="'.get_permalink().'">';
  133.                         $shrt_cd .= get_the_title();
  134.                         $shrt_cd .= '</a></li>';
  135.                     endwhile; endif;
  136.                     $shrt_cd .= '</ul>';
  137.                     $shrt_cd .= "[/accordion]";
  138.                     echo do_shortcode( $shrt_cd );
  139.                     wp_reset_query();
  140.                 ?>
  141.             </div><!-- accordion-single -->
  142.             <?php $i++; ?>
  143.             <?php if ($i == 2) {
  144.                 genesis_after_post_content();
  145.                 genesis_before_comments();
  146.                 genesis_after_comments();
  147.                 genesis_before_pings();
  148.                 genesis_after_pings();
  149.                 genesis_before_comment_form();
  150.                 genesis_comment_form();
  151.                 genesis_after_comment_form();
  152.             } ?>
  153.             <?php return $wp_query->current_post + 1 < $wp_query->post_count;?>
  154.         <?php }; ?>
  155.     <?php $i++; ?>
  156.     <?php endwhile; ?>
  157.     <?php genesis_after_endwhile(); ?>
  158.     <?php endif; ?>
  159.     <?php genesis_after_loop(); ?>
  160.     <?php genesis_after_content_sidebar_wrap(); ?>
  161.     <?php genesis_before_footer(); ?>
  162.     <?php genesis_after_footer(); ?>
  163. <?php
  164. }
  165. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement