daily pastebin goal
58%
SHARE
TWEET

Functions.php

jbculp Aug 10th, 2018 (edited) 54 in 3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. /* ! Loop Customizations */
  5.  
  6. add_action('genesis_before_loop', 'dmeyers_pre_loop');
  7.  
  8. function dmeyers_pre_loop() {
  9.     if (is_page()) {
  10.         // overide the Genesis loop
  11.         remove_action('genesis_loop', 'genesis_do_loop');
  12.         add_action('genesis_loop', 'dmeyers_page_loop');
  13.     } else {
  14.         // open columns markup
  15.         dmeyers_open_columns();
  16.        
  17.        
  18.         // add post hook for conditional customizations
  19.         add_action('genesis_before_post', 'dmeyers_before_post');
  20.         add_action('genesis_after_post', 'dmeyers_post_reset');
  21.        
  22.        
  23.         // close the columns after the loop
  24.         add_action('genesis_after_loop', 'dmeyers_close_columns');
  25.     }
  26. }
  27. /* ! Columns Markup */
  28.  
  29. function dmeyers_open_columns() {
  30.     echo '<div class="columns"><div class="column-blurb"></div> <!-- end .blurb --><div class="column-featured">';
  31. }
  32.  
  33. function dmeyers_close_columns() {
  34.     echo '</div> <!-- end .column-featured --> </div> <!-- end .columns -->';
  35. }
  36.  
  37.  
  38. /* ! Post Customizations */
  39.  
  40. function dmeyers_before_post() {
  41.  
  42.   if (get_post_type() == 'dmeyers_product') {
  43.         // alter the info & meta output
  44.         add_filter('genesis_post_info', 'dmeyers_product_info');
  45.         add_filter('genesis_post_meta', 'dmeyers_product_meta');
  46.        
  47.         if (is_singular() ) {
  48.             // show the featured image on a product's page
  49.             add_action('genesis_post_content', 'dmeyers_product_image');
  50.         }
  51.     }
  52. }
  53.  
  54. function dmeyers_post_reset() {
  55.     remove_filter('genesis_post_info', 'dmeyers_product_info');
  56.     remove_filter('genesis_post_meta', 'dmeyers_product_meta');
  57. }
  58.  
  59.  
  60. /* ! Catalog Products Customizations */
  61.  
  62. function dmeyers_product_image() {
  63.     $img = genesis_get_image(array(
  64.         'format' => 'html',
  65.         'size' => 'medium',
  66.         'attr' => array(
  67.             'class' => 'alignleft post-image')
  68.         )
  69.     );
  70.    
  71.     echo $img;
  72. }
  73.  
  74. function dmeyers_product_info($post_info) {
  75.     $post_info = '[post_edit]';
  76.    
  77.     return $post_info;
  78. }
  79.  
  80. function dmeyers_product_meta($post_meta) {
  81.     $post_meta = '[post_terms taxonomy="dmeyers_collection"]';
  82.    
  83.     return $post_meta;
  84. }
  85.  
  86.  
  87. /* ! Pages Loop */
  88.  
  89. function dmeyers_page_loop() {
  90.    
  91.     global $more;
  92.     if ( have_posts() ) : while ( have_posts() ) : the_post();
  93.         // split the content into columns based on the <!--more--> content tag
  94.         // http://codex.wordpress.org/Function_Reference/the_content
  95.        
  96.         // get the teaser content (before "more")
  97.         $more = 0;
  98.         $blurb_content = get_the_content('', true);
  99.        
  100.         // get the content without the teaser
  101.         $more = 1;
  102.         $featured_content = get_the_content('', true);
  103.        
  104.         if ($featured_content === $blurb_content) {
  105.             $featured_content = '';
  106.         } else {
  107.             add_filter('the_content', 'dmeyers_strip_more_span', 5);
  108.         }
  109.        
  110.        
  111.         // get the featured image URL
  112.         // http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
  113.        
  114.         if (has_post_thumbnail() ) {
  115.             $featured_image = wp_get_attachment_image_src(
  116.                 get_post_thumbnail_id($post->ID),
  117.                 'column-fill'
  118.             );
  119.         }
  120.         ?>
  121.         <div <?php post_class('columns'); ?> <?php echo (has_post_thumbnail()) ? 'style="background-image: url(' . $featured_image[0] . ');"' : ''; ?>>
  122.        
  123.             <div class="column-blurb">
  124.                
  125.                 <?php do_action( 'genesis_before_post_title' ); ?>
  126.                 <?php do_action( 'genesis_post_title' ); ?>
  127.                 <?php do_action( 'genesis_after_post_title' ); ?>
  128.                
  129.                 <div class="entry-content">
  130.                     <?php echo apply_filters('the_content', $blurb_content); ?>
  131.                     <?php apply_filters( 'genesis_edit_post_link', true ) ? edit_post_link( __( '(Edit)', 'genesis' ), '', '' ) : ''; ?>
  132.                 </div><!-- end .entry-content -->
  133.             </div> <!-- end .column-blurb -->
  134.            
  135.             <div <?php if (is_page != 1028); ?> class="column-featured">
  136.                 <?php do_action( 'genesis_before_post_content' ); ?>
  137.                 <div class="entry-content">
  138.                     <?php echo apply_filters('the_content', $featured_content); ?>
  139.                 </div><!-- end .entry-content -->
  140.                 <?php do_action( 'genesis_after_post_content' ); ?>
  141.                
  142.             </div> <!-- end .column-feature -->
  143.            
  144.         </div> <!-- end .postclass.columns -->
  145.            
  146. <?php
  147.  
  148.         // reset filters
  149.         remove_filter('the_content', 'dmeyers_strip_more_span', 5);
  150.        
  151.        
  152.         do_action( 'genesis_after_post' );
  153.         $loop_counter++;
  154.    
  155.         endwhile; /** end of one post **/
  156.         do_action( 'genesis_after_endwhile' );
  157.    
  158.         else : /** if no posts exist **/
  159.         do_action( 'genesis_loop_else' );
  160.         endif; /** end loop **/
  161. }
  162.  
  163.  
  164. /* ! Gallery Menu loop */
  165. // Creates a gallery menu from from the specified collection.
  166.  
  167. function dmeyers_gallery_menu_loop($args) {
  168.     global $wp_query;
  169.    
  170.    
  171.     // open gallery markup
  172. ?>
  173.         <div class="gallery-menu">
  174.             <a class="prev browse left"></a>
  175.             <div class="scrollable">
  176.                 <div class="items">
  177. <?php
  178.     // loop through the target collection's products
  179.     $wp_query = new WP_Query($args);
  180.    
  181.     $thumb_count = 1;  // thumbs output counter
  182.     $per_row = 6;  // number of thumbs visible per row/group
  183.    
  184.     if (have_posts()) : while (have_posts()) : the_post();
  185.        
  186.         // only display thumb if featured image set
  187.         if (has_post_thumbnail()) :
  188.            
  189.             // open a new row
  190.             echo (($thumb_count - 1) % $per_row == 0) ? '<div class="row">' : '';
  191.            
  192.            
  193.             // get the image's large version info
  194.             $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
  195.            
  196.             // get the image's description
  197.             $description = apply_filters('the_content', get_the_content());
  198.            
  199.             // sanitize the description for use in JavaScript/the data attribute
  200.             $description_attr = sanitize_post_field('post_content', $description, get_the_ID(), 'js');
  201.             $description_attr = str_replace('\n', '', $description_attr);  // remove "\n" from editor line breaks
  202.            
  203.            
  204.             // output the thumb
  205. ?>
  206.                     <a class="thumb" href="<?php echo $large_image_url[0]; ?>" title="<?php the_title_attribute(); ?>" data-description="<?php echo $description_attr; ?>">
  207.                         <?php the_post_thumbnail('gallery-thumb'); ?>
  208.                     </a>
  209. <?php
  210.             // close the row
  211.             echo (($wp_query->current_post + 1 == $wp_query->post_count) || ($thumb_count % $per_row == 0)) ? '</div>' : '';
  212.            
  213.            
  214.             $thumb_count++;
  215.         endif;
  216.        
  217.        
  218.     // end of post
  219.     endwhile;
  220.    
  221.    
  222.     // end of loop
  223.     endif;
  224.    
  225.    
  226.     // Restore original query
  227.     wp_reset_query();
  228.    
  229.        
  230.     // close the gallery markup
  231. ?>
  232.                 </div>
  233.             </div>
  234.             <a class="next browse right"></a>
  235.         </div> <!-- end .gallery-menu -->
  236. <?php
  237. }
  238.  
  239.  
  240. /* ! Other Filters */
  241.  
  242. // Removes "more" tag's generated span from the post-teaser content.
  243. function dmeyers_strip_more_span($content) {
  244.     return preg_replace('/<span id="more-\d+"><\/span>/', null, $content);
  245. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top