Guest User

Custom loop, not grid, Genesis

a guest
Feb 3rd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.58 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Display the Tip of the Day Custom Post Type archive custom fields using
  6.  * ACF.
  7.  *
  8.  * @author Angie Meeker
  9.  * @uses   Advanced Custom Fields
  10.  */
  11.  
  12.  add_action('genesis_entry_content','genesis_do_post_title', 2);
  13.  
  14.  //* Removes Continue Reading from the echoed excerpt
  15.  function sbt_auto_excerpt_more( $more ) {
  16. return 'aaa';
  17. }
  18. add_filter( 'excerpt_more', 'sbt_auto_excerpt_more', 20 );
  19.  
  20. function sbt_custom_excerpt_more( $output ) {return preg_replace('/<a[^>]+>Continue reading.*?<\/a>/i','',$output);
  21. }
  22. add_filter( 'get_the_excerpt', 'sbt_custom_excerpt_more', 20 );
  23.  
  24.  
  25.  //* Add Tip of the Day body class to the head
  26. add_filter( 'body_class', 'add_tiparchives_body_class' );
  27. function add_tiparchives_body_class( $classes ) {
  28.    $classes[] = 'tiparchives-post-type-archive-{tipoftheday}';
  29.    return $classes;
  30. }
  31.  
  32.  // Return Category and Tip of the Day on Single Posts
  33. add_action ( 'genesis_before_content', 'show_totd', 9 );
  34. function show_totd() {
  35.     echo '<div class="totd-cats-title">Tip of the Day</div>';
  36. }
  37.   // Remove Post Author
  38.  add_filter( 'genesis_post_info', 'remove_post_author_totd_posts' );
  39. function remove_post_author_totd_posts($post_info) {
  40.     $post_info = '[post_date]';
  41.     return $post_info;
  42. }
  43.  
  44. function be_custom_loop_feature() {
  45.     global $post;
  46.  
  47.     // arguments, adjust as needed
  48.     $args = array(
  49.         'post_type'      => 'post',
  50.         'posts_per_page' => 1,
  51.         'post_status'    => 'publish',
  52.         'paged'          => get_query_var( 'paged' )
  53.     );
  54.  
  55.     /*
  56.     Overwrite $wp_query with our new query.
  57.     The only reason we're doing this is so the pagination functions work,
  58.     since they use $wp_query. If pagination wasn't an issue,
  59.     use: https://gist.github.com/3218106
  60.     */
  61.     global $wp_query;
  62.     $wp_query = new WP_Query( $args );
  63.  
  64.     if ( have_posts() ) :
  65.         echo '<ul>';
  66.         while ( have_posts() ) : the_post();
  67.  
  68.             // Return if CPT Tip of the Day
  69. add_action( 'genesis_after_entry_content', 'manta_tips_pre', 15 );
  70. function manta_tips_pre() {
  71.  
  72.         // Store the pre tips data
  73.         $tips_data_pre = array(
  74.                 'totd_tags' => get_field( 'totd_tags' ),
  75.                 'tip_article_headline' => get_field( 'tip_article_headline' ),
  76.                 'article_author' => get_field( 'article_author' ),
  77.                 'article_author_link' => get_field( 'article_author_link' ),
  78.         );
  79.        
  80.  
  81. // Only output if we have tips data    
  82.         if ($tips_data_pre['totd_tags'] != '' ||
  83.                 $tips_data_pre['tip_article_headline'] != '' ||
  84.                 $tips_data_pre['article_author'] != '' ||
  85.                 $tips_data_pre['article_author_link'] != '') {
  86.                
  87.                 echo '<div class="tip-excerpt"><p><div class="entry-content">';
  88.                                
  89.                                 echo '<div class="entry-terms">' , do_shortcode('[post_terms taxonomy="totd_tags" before="See More Tips For: " taxonomy="totd_tags"] '),'</div>' ;
  90.                                 echo '<div class="entry-terms">
  91.                                                                                <div class="share">Share This Tip:</div>
  92.                                                                                        <div class="addthis_toolbox addthis_default_style">
  93.                                                                                                <a class="addthis_button_preferred_1"></a>
  94.                                                                                                <a class="addthis_button_preferred_2"></a>
  95.                                                                                                <a class="addthis_button_preferred_3"></a>
  96.                                                                                                <a class="addthis_button_preferred_4"></a>
  97.                                                                                                <a class="addthis_button_compact"></a>
  98.                                                                                                <a class="addthis_counter addthis_bubble_style"></a>
  99.                                                                                        </div>
  100.                                                                                        <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=manta"></script>
  101.                                                                                </div>
  102.                                                                </div></div>';
  103.  
  104.                                
  105.                 echo '</p><div class="divider"></div>';
  106.         }
  107. }
  108.  
  109.         endwhile;
  110.         echo '</ul>';
  111.         do_action( 'genesis_after_endwhile' );
  112.     endif;
  113.  
  114.     wp_reset_query();
  115. }
  116.  
  117.  
  118. function be_custom_loop_teasers() {
  119.     global $post;
  120.  
  121.     // arguments, adjust as needed
  122.     $args = array(
  123.         'post_type'      => 'post',
  124.         'posts_per_page' => 20,
  125.         'post_status'    => 'publish',
  126.         'paged'          => get_query_var( 'paged' )
  127.     );
  128.  
  129.     // Use $loop, a custom variable we made up, so it doesn't overwrite anything
  130.     $loop = new WP_Query( $args );
  131.  
  132.     // have_posts() is a wrapper function for $wp_query->have_posts(). Since we
  133.     // don't want to use $wp_query, use our custom variable instead.
  134.     if ( $loop->have_posts() ) :
  135.         echo '<ul>';
  136.         while ( $loop->have_posts() ) : $loop->the_post();
  137.  
  138.             // Return if CPT Tip of the Day
  139. add_action( 'genesis_after_entry_content', 'manta_tips_teaser_pre', 15 );
  140. function manta_tips_teaser_pre() {
  141.  
  142.         // Store the pre tips data
  143.         $tips_data_pre = array(
  144.                 'totd_tags' => get_field( 'totd_tags' ),
  145.         );
  146.        
  147.  
  148. // Only output if we have tips data    
  149.         if ($tips_data_pre['totd_tags'] !='') {
  150.                {
  151.                 echo '<div class="tip-excerpt"><p><div class="entry-content">';
  152.                                
  153.                                 echo '<div class="entry-terms">' , do_shortcode('[post_terms taxonomy="totd_tags" before="See More Tips For: " taxonomy="totd_tags"] '),'</div>' ;
  154.                                                                 </div></div>';
  155.                echo '</p><div class="divider"></div>';
  156.                 endwhile;
  157.         echo '</ul>';
  158.         do_action( 'genesis_after_endwhile' );
  159.     endif;
  160.  
  161.     // We only need to reset the $post variable. If we overwrote $wp_query,
  162.     // we'd need to use wp_reset_query() which does both.
  163.     wp_reset_postdata();
  164. }
  165. }
  166. }
  167.  
  168. add_action( 'genesis_loop', 'be_custom_loop_feature' );
  169. add_action( 'genesis_loop', 'be_custom_loop_teasers' );
  170. remove_action( 'genesis_loop', 'genesis_do_loop' );
  171.  
  172.  
  173. genesis();
Advertisement
Add Comment
Please, Sign In to add comment