Advertisement
Guest User

Advanced Custom Fields in Loop

a guest
Jun 28th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.64 KB | None | 0 0
  1. <?php
  2. global $avia_config, $post_loop_count;
  3.  
  4.  
  5. if(empty($post_loop_count)) $post_loop_count = 1;
  6. $blog_style = !empty($avia_config['blog_style']) ? $avia_config['blog_style'] : avia_get_option('blog_style','multi-big');
  7. if(is_single()) $blog_style = avia_get_option('single_post_style','single-big');
  8.  
  9. $blog_global_style = avia_get_option('blog_global_style',''); //alt: elegant-blog
  10.  
  11.  
  12. $initial_id = avia_get_the_ID();
  13.  
  14. // check if we got posts to display:
  15. if (have_posts()) :
  16.  
  17.     while (have_posts()) : the_post();
  18.  
  19.     /*
  20.      * get the current post id, the current post class and current post format
  21.      */
  22.     $url = "";
  23.     $current_post = array();
  24.     $current_post['post_loop_count']= $post_loop_count;
  25.     $current_post['the_id']     = get_the_ID();
  26.     $current_post['parity']     = $post_loop_count % 2 ? 'odd' : 'even';
  27.     $current_post['last']       = count($wp_query->posts) == $post_loop_count ? " post-entry-last " : "";
  28.     $current_post['post_type']  = get_post_type($current_post['the_id']);
  29.     $current_post['post_class']     = "post-entry-".$current_post['the_id']." post-loop-".$post_loop_count." post-parity-".$current_post['parity'].$current_post['last']." ".$blog_style;
  30.     $current_post['post_class'] .= ($current_post['post_type'] == "post") ? '' : ' post';
  31.     $current_post['post_format']    = get_post_format() ? get_post_format() : 'standard';
  32.     $current_post['post_layout']    = avia_layout_class('main', false);
  33.     $blog_content = !empty($avia_config['blog_content']) ? $avia_config['blog_content'] : "content";
  34.    
  35.     /*If post uses builder change content to exerpt on overview pages*/
  36.     if(AviaHelper::builder_status($current_post['the_id']) && !is_singular($current_post['the_id']) && $current_post['post_type'] == 'post')
  37.     {
  38.        $current_post['post_format'] = 'standard';
  39.        $blog_content = "excerpt_read_more";
  40.     }
  41.    
  42.    
  43.     /*
  44.      * retrieve slider, title and content for this post,...
  45.      */
  46.     $size = strpos($blog_style, 'big') ? (strpos($current_post['post_layout'], 'sidebar') !== false) ? 'entry_with_sidebar' : 'entry_without_sidebar' : 'square';
  47.    
  48.     if(!empty($avia_config['preview_mode']) && !empty($avia_config['image_size']) && $avia_config['preview_mode'] == 'custom') $size = $avia_config['image_size'];
  49.     $current_post['slider']     = get_the_post_thumbnail($current_post['the_id'], $size);
  50.    
  51.     if(is_single($initial_id) && get_post_meta( $current_post['the_id'], '_avia_hide_featured_image', true ) ) $current_post['slider'] = "";
  52.    
  53.    
  54.     $current_post['title']      = get_the_title();
  55.     $current_post['content']    = $blog_content == "content" ? get_the_content(__('Read more','avia_framework').'<span class="more-link-arrow"></span>') : get_the_excerpt();
  56.     $current_post['content']    = $blog_content == "excerpt_read_more" ? $current_post['content'].'<div class="read-more-link"><a href="'.get_permalink().'" class="more-link">'.__('Read more','avia_framework').'<span class="more-link-arrow"></span></a></div>' : $current_post['content'];
  57.     $current_post['before_content'] = "";
  58.  
  59.     /*
  60.      * ...now apply a filter, based on the post type... (filter function is located in includes/helper-post-format.php)
  61.      */
  62.     $current_post   = apply_filters( 'post-format-'.$current_post['post_format'], $current_post );
  63.     $with_slider    = empty($current_post['slider']) ? "" : "with-slider";
  64.     /*
  65.      * ... last apply the default wordpress filters to the content
  66.      */
  67.      
  68.    
  69.     $current_post['content'] = str_replace(']]>', ']]&gt;', apply_filters('the_content', $current_post['content'] ));
  70.  
  71.     /*
  72.      * Now extract the variables so that $current_post['slider'] becomes $slider, $current_post['title'] becomes $title, etc
  73.      */
  74.     extract($current_post);
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.     /*
  84.      * render the html:
  85.      */
  86.  
  87.     echo "<article class='".implode(" ", get_post_class('post-entry post-entry-type-'.$post_format . " " . $post_class . " ".$with_slider))."' ".avia_markup_helper(array('context' => 'entry','echo'=>false)).">";
  88.        
  89.        
  90.        
  91.         //default link for preview images
  92.         $link = !empty($url) ? $url : get_permalink();
  93.        
  94.         //preview image description
  95.         $desc = get_post( get_post_thumbnail_id() );
  96.         if(is_object($desc))  $desc = $desc -> post_excerpt;
  97.         $featured_img_desc = ( $desc != "" ) ? $desc : the_title_attribute( 'echo=0' );
  98.  
  99.         //on single page replace the link with a fullscreen image
  100.         if(is_singular())
  101.         {
  102.             $link = avia_image_by_id(get_post_thumbnail_id(), 'large', 'url');
  103.         }
  104.  
  105.  
  106.         //echo preview image
  107.         if( strpos($blog_global_style, 'elegant-blog') === false )
  108.         {
  109.             if(strpos($blog_style, 'big') !== false)
  110.             {
  111.                 if($slider) $slider = '<a href="'.$link.'" title="'.$featured_img_desc.'">'.$slider.'</a>';
  112.                 if($slider) echo '<div class="big-preview '.$blog_style.'">'.$slider.'</div>';
  113.             }
  114.            
  115.             if(!empty($before_content))
  116.                 echo '<div class="big-preview '.$blog_style.'">'.$before_content.'</div>';
  117.         }
  118.        
  119.         echo "<div class='blog-meta'>";
  120.  
  121.         $blog_meta_output = "";
  122.         $icon =  '<span class="iconfont" '.av_icon_string($post_format).'></span>';
  123.  
  124.             if(strpos($blog_style, 'multi') !== false)
  125.             {
  126.                 $gravatar = "";
  127.                 $link = get_post_format_link($post_format);
  128.                 if($post_format == 'standard')
  129.                 {
  130.                     $author_name = apply_filters('avf_author_name', get_the_author_meta('display_name', $post->post_author), $post->post_author);
  131.                     $author_email = apply_filters('avf_author_email', get_the_author_meta('email', $post->post_author), $post->post_author);
  132.                    
  133.                     $gravatar_alt = esc_html($author_name);
  134.                     $gravatar = get_avatar($author_email, '81', "blank", $gravatar_alt);
  135.                     $link = get_author_posts_url($post->post_author);
  136.                 }
  137.  
  138.                 $blog_meta_output = "<a href='{$link}' class='post-author-format-type'><span class='rounded-container'>".$gravatar.$icon."</span></a>";
  139.             }
  140.             else if(strpos($blog_style, 'small')  !== false)
  141.             {
  142.                 $blog_meta_output = "<a href='{$link}' class='small-preview' title='{$featured_img_desc}'>".$slider.$icon."</a>";
  143.             }
  144.  
  145.         echo apply_filters('avf_loop_index_blog_meta', $blog_meta_output);
  146.  
  147.         echo "</div>";
  148.  
  149.         echo "<div class='entry-content-wrapper clearfix {$post_format}-content'>";
  150.             echo '<header class="entry-content-header">';
  151.                
  152.                 $content_output  =  '<div class="entry-content" '.avia_markup_helper(array('context' => 'entry_content','echo'=>false)).'>';
  153.                 $content_output .=  $content;
  154.                 $content_output .=  '</div>';
  155.                
  156.                
  157.                 $taxonomies  = get_object_taxonomies(get_post_type($the_id));
  158.                 $cats = '';
  159.                 $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') );
  160.                 $excluded_taxonomies = apply_filters('avf_exclude_taxonomies', $excluded_taxonomies, get_post_type($the_id), $the_id);
  161.  
  162.                 if(!empty($taxonomies))
  163.                 {
  164.                     foreach($taxonomies as $taxonomy)
  165.                     {
  166.                         if(!in_array($taxonomy, $excluded_taxonomies))
  167.                         {
  168.                             $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';
  169.                         }
  170.                     }
  171.                 }
  172.                
  173.                
  174.                
  175.                 //elegant blog
  176.                 //prev: if( $blog_global_style == 'elegant-blog' )
  177.                 if( strpos($blog_global_style, 'elegant-blog') !== false )
  178.                 {
  179.                     $cat_output = "";
  180.                    
  181.                     if(!empty($cats))
  182.                     {
  183.                         $cat_output .= '<span class="blog-categories minor-meta">';
  184.                         $cat_output .= $cats;
  185.                         $cat_output .= '</span>';
  186.                         $cats = "";
  187.                     }
  188.            
  189.                     echo strpos($blog_global_style, 'modern-blog') === false ? $cat_output.$title : $title.$cat_output;
  190.                    
  191.                     echo '<span class="av-vertical-delimiter"></span>';
  192.                    
  193.                     //echo preview image
  194.                     if(strpos($blog_style, 'big') !== false)
  195.                     {
  196.                         if($slider) $slider = '<a href="'.$link.'" title="'.$featured_img_desc.'">'.$slider.'</a>';
  197.                         if($slider) echo '<div class="big-preview '.$blog_style.'">'.$slider.'</div>';
  198.                     }
  199.                    
  200.                     if(!empty($before_content))
  201.                         echo '<div class="big-preview '.$blog_style.'">'.$before_content.'</div>';
  202.                    
  203.                    
  204.                     echo $content_output;
  205.                    
  206.                     $cats = "";
  207.                     $title = "";
  208.                     $content_output = "";
  209.                 }
  210.                
  211.                
  212.                
  213.                
  214.                 echo $title;
  215.                
  216.                 echo "<span class='post-meta-infos'>";
  217.                
  218.                 echo "<time class='date-container minor-meta updated' >".get_the_time(get_option('date_format'))."</time>";
  219.                 echo "<span class='text-sep text-sep-date'>/</span>";
  220.  
  221.  
  222.  
  223.                     if ( get_comments_number() != "0" || comments_open() ){
  224.  
  225.                     echo "<span class='comment-container minor-meta'>";
  226.                     comments_popup_link(  "0 ".__('Comments','avia_framework'),
  227.                                           "1 ".__('Comment' ,'avia_framework'),
  228.                                           "% ".__('Comments','avia_framework'),'comments-link',
  229.                                           "".__('Comments Disabled','avia_framework'));
  230.                     echo "</span>";
  231.                     echo "<span class='text-sep text-sep-comment'>/</span>";
  232.                     }
  233.  
  234.  
  235.                     if(!empty($cats))
  236.                     {
  237.                         echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." ";
  238.                         echo $cats;
  239.                         echo '</span><span class="text-sep text-sep-cat">/</span>';
  240.                     }
  241.  
  242.  
  243.                     echo '<span class="blog-author minor-meta">'.__('by','avia_framework')." ";
  244.                     echo '<span class="entry-author-link" >';
  245.                     echo '<span class="vcard author"><span class="fn">';
  246.                     the_author_posts_link();
  247.                     echo '</span></span>';
  248.                     echo '</span>';
  249.                     echo '</span>';
  250.                 echo '</span>';
  251.             echo '</header>';
  252.  
  253.  
  254.             // echo the post content
  255.            
  256.            
  257.              // OUTPUT FROM ADVANCED CUSTOM FIELDS PLUGIN
  258.                                    
  259.                             $letterLinkText         = get_field('letter_link_text');
  260.                             $letterPdf              = get_field('letter_pdf');
  261.                             $letterResponse         = get_field('response');
  262.                             $letterResponseLinkText = get_field('response_link_text');
  263.                             $letterResponsePdf      = get_field('response_pdf');
  264.                            
  265.                             echo '<br><h5>Water Authority Letter</h5>';
  266.     echo '<a href="'.$letterPdf.'" target="_blank">' . get_field('letter_link_text') . '</a>';
  267.  
  268.                             echo '<br><br><h5 class="respons">MWD\'s Response</h5>';
  269.                            
  270.     if($letterResponse == "yes") {
  271.                                 echo ('<a href="'.$letterResponsePdf.'" target="_blank" class="letterRowA">'.$letterResponseLinkText.'</a>');          
  272.            
  273.             } elseif($letterResponse == "no") {
  274.                                 echo ('<br><img src="/mwd/wp-content/uploads/no-response.jpg">');
  275.                             }
  276.             echo '<br><br><hr>';
  277.            
  278.             // END OUTPUT FROM ADVANCED CUSTOM FIELDS PLUGIN
  279.                
  280.            
  281.             echo $content_output;
  282.  
  283.             echo '<footer class="entry-footer">';
  284.  
  285.             $avia_wp_link_pages_args = apply_filters('avf_wp_link_pages_args', array(
  286.                                                                                     'before' =>'<nav class="pagination_split_post">'.__('Pages:','avia_framework'),
  287.                                                                                     'after'  =>'</nav>',
  288.                                                                                     'pagelink' => '<span>%</span>',
  289.                                                                                     'separator'        => ' ',
  290.                                                                                     ));
  291.  
  292.             wp_link_pages($avia_wp_link_pages_args);
  293.  
  294.             if(is_single() && !post_password_required())
  295.             {
  296.                 //tags on single post
  297.                 if(has_tag())
  298.                 {
  299.                     echo '<span class="blog-tags minor-meta">';
  300.                     the_tags('<strong>'.__('Tags:','avia_framework').'</strong><span> ');
  301.                     echo '</span></span>';
  302.                 }
  303.                
  304.                 //share links on single post
  305.                 avia_social_share_links();
  306.    
  307.             }
  308.            
  309.             do_action('ava_after_content', $the_id, 'post');
  310.  
  311.             echo '</footer>';
  312.  
  313.         echo "<div class='post_delimiter'></div>";
  314.         echo "</div>";
  315.         echo "<div class='post_author_timeline'></div>";
  316.         echo av_blog_entry_markup_helper($current_post['the_id']);
  317.     echo "</article>";
  318.  
  319.     $post_loop_count++;
  320.     endwhile;
  321.     else:
  322.  
  323. ?>
  324.  
  325.     <article class="entry">
  326.         <header class="entry-content-header">
  327.             <h1 class='post-title entry-title'><?php _e('Nothing Found', 'avia_framework'); ?></h1>
  328.         </header>
  329.  
  330.         <p class="entry-content" <?php avia_markup_helper(array('context' => 'entry_content')); ?>><?php _e('Sorry, no posts matched your criteria', 'avia_framework'); ?></p>
  331.  
  332.         <footer class="entry-footer"></footer>
  333.     </article>
  334.  
  335. <?php
  336.  
  337.     endif;
  338.  
  339.     if(empty($avia_config['remove_pagination'] ))
  340.     {
  341.         echo "<div class='{$blog_style}'>".avia_pagination('', 'nav')."</div>";
  342.     }
  343. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement