RUSSEL86

ACF emergency code

Dec 2nd, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.04 KB | None | 0 0
  1. ///Repeater – Only Display First 3 Rows///
  2. --------------------------------------
  3. <?php
  4. if( have_rows('latest_offers', 'options') ):
  5.     $i = 0;
  6.     while ( have_rows('latest_offers', 'options') ) : the_row(); ?>
  7.         <?php $i++; ?>
  8.         <?php if( $i > 3 ):
  9.             <?php break; ?>
  10.         <?php endif; ?>
  11.        
  12.         <a href="<?php the_sub_field('page_link'); ?>" class="hot">
  13.             <div class="img"><img src="<?php the_sub_field('brand_logo'); ?>" alt=""></div>
  14.             <div class="text">
  15.                 <div class="smlltxt"><?php the_sub_field('heading'); ?></div>
  16.                 <div class="num"><?php the_sub_field('price'); ?></div>
  17.                 <div class="txt"><?php the_sub_field('description'); ?></div>
  18.             </div>
  19.             <img src="<?php echo get_template_directory_uri(); ?>/img/hot.png" alt="" class="hot_img">
  20.         </a>
  21.    
  22.     <?php endwhile;
  23. endif;?>
  24.  
  25.  
  26. //Repeater field content into Group field
  27. ----------------------------------------------
  28. <?php if( have_rows('installation_option_area', 'option') ):
  29. while( have_rows('installation_option_area', 'option') ): the_row(); ?>
  30. <div class="comon_black_title fix">
  31. <h1><?php the_sub_field('installation_option_title'); ?></h1>
  32. </div>
  33. <div class="instal_optios_wrapper fix">                
  34. <?php if( have_rows('installation_option_item_area') ): ?>
  35. <?php   while( have_rows('installation_option_item_area') ): the_row(); ?>
  36.       <div class="col-md-4  col-sm-4">
  37.             <div class="instal_optios_item fix">
  38.                 <a href="<?php the_sub_field('item_link'); ?>">
  39.                     <div class="instal_optios_thumb fix">
  40.                         <img src="<?php the_sub_field('item_image'); ?>" alt="">
  41.                     </div>
  42.                 </a>
  43.                 <div class="instal_optios_text fix">
  44.                     <h4><?php the_sub_field('item_title'); ?></h4>
  45.                     <p><?php the_sub_field('item_textarea'); ?> </p>
  46.                     </div>
  47.             </div>
  48.         </div> 
  49. <?php endwhile; endif; ?>
  50. </div>
  51. <?php endwhile; endif; ?>  
  52.  
  53. //Unique ID for Repeater Field
  54. <?php if(get_field('repeater_field_name')): $i = 0; ?>
  55.     <ul>
  56.     <?php while(has_sub_field('repeater_field_name')): $i++; ?>
  57.         <li class="section-<?php echo $i; ?>">
  58.             sub_field_1 = <?php the_sub_field('sub_field_1'); ?>, sub_field_2 = <?php the_sub_field('sub_field_2'); ?>, etc
  59.         </li>
  60.     <?php endwhile; ?>
  61.     </ul>
  62. <?php endif; ?>
  63.  
  64. // acf gallery into repeater with fancybox lightbox dynamic code
  65. =============================================================
  66. <?php if( have_rows('package_sidebar_galley') ): ?>
  67.     <div class="packge_extens_content_galeryrht fix">
  68.         <?php $gallery_count=1;
  69.         while( have_rows('package_sidebar_galley') ): the_row();
  70.         ?>
  71.         <div class="packge_extens_galeryrht_single fix">
  72.             <?php
  73.                 $images = get_sub_field('sidebar_gallery');
  74.                 $img_count=1;
  75.                 if( $images ): ?>
  76.                                            
  77.             <?php
  78.                 foreach( $images as $image ):
  79.                 if ($img_count == 1) { ?>
  80.                                    
  81.                 <img src="<?php echo $image['url']; ?>" alt="" />
  82.                                
  83.                 <a rel="gallery<?php echo $gallery_count;?>" class="more_galtext various_popup" href="<?php echo $image['url']; ?>">More Package Photos</a>
  84.                                        
  85.                 <?php }else {?>
  86.                                        
  87.                 <a rel="gallery<?php echo $gallery_count;?>" class="various_popup" href="<?php echo $image['url']; ?>"></a>
  88.                                        
  89.                 <?php }  
  90.                
  91.                 $img_count++;
  92.                 endforeach;
  93.                 endif;
  94.                
  95.                 ?>
  96.                                
  97.         </div>
  98.        
  99.     <?php
  100.     $gallery_count++;
  101.     endwhile; ?>
  102.  
  103.     </div>
  104.  
  105. <?php endif; ?>
  106.  
  107. // post object display code if not work acf example code
  108. ========================================================
  109. <?php $post_objects = get_field('house_fleet_title');   ?>     
  110. <p><a href="<?php echo get_permalink($post_objects->ID); ?>"><?php echo get_the_title($post_objects->ID); ?></a></p>
  111.  
  112. // Display the First image from gallery
  113. ==========================================
  114. <?php  $images = get_field('image_for_light_box');
  115.         if( $images ): $image_1 = $images[0]; ?>                
  116.                 <a class="install_fancybox" rel="prettyPhoto[ins_gal<?php the_ID(); ?>]" href="<?php echo $image_1['url']; ?>" >
  117.                     <img src="<?php echo $image_1['sizes']['medium']; ?>" alt="" />
  118.                 </a>
  119.         <?php endif; ?>
  120.  
  121. // Exclude the First image from gallery
  122. =======================================
  123. <?php $gallimages = get_field('image_for_light_box');
  124. for ($i=0; $i<1; $i++){
  125. if (!empty($gallimages)) {
  126. $remove = array_shift($gallimages);
  127. }
  128. }
  129.  
  130. if( $gallimages ): ?>
  131.  
  132. <div class="install_gallthumb_small">
  133. <?php foreach( $gallimages as $gimage ): ?>
  134.  
  135. <div class="gallthumb_small_single">
  136. <a class="install_fancybox" rel="prettyPhoto[ins_gal<?php the_ID(); ?>]" href="<?php echo $gimage['url']; ?>" >
  137. <img src="<?php echo $gimage['sizes']['thumbnail']; ?>" alt="" />
  138. </a>
  139. </div>
  140. <?php endforeach; ?>
  141.  
  142. </div>
  143. <?php endif; ?>
  144.  
  145. or if you want to skip couple of item then mention how many as a example for skip first 4 item
  146. -----------------------------------------------------------------------
  147. for ($i=0; $i<4; $i++){
  148. if (!empty($gallimages)) {
  149. $remove = array_shift($gallimages);
  150. }
  151. }
  152.  
  153. // display acf field item on wocommerce category page.
  154. -------------------------------------------------
  155. <?php $queriedObject = get_queried_object();
  156.       $category_image = get_field('category_image','product_cat_'.$queriedObject->term_id);?>
  157. <?php if($category_image) :?>
  158. <div class="catalog_top_images_new row">
  159.     <img src="<?php echo $category_image;?>" alt="" />
  160. </div>
  161. <?php endif; ?>
  162.  
  163. //combine meta value for wp query acf repeater field
  164. function my_posts_where( $where ) {
  165. global $wpdb;
  166. $where = str_replace(
  167. "meta_key = 'feature_latest_list_%",
  168. "meta_key LIKE 'feature_latest_list_%",
  169. $wpdb->remove_placeholder_escape($where)
  170. );
  171. return $where;
  172. }
  173.  
  174. add_filter('posts_where', 'my_posts_where');
  175.  
  176. // show all checkbox label and value
  177. <?php $my_post = new WP_Query(array(
  178. 'post_type' => 'programs-items',
  179. ));
  180. if($my_post -> have_posts()):
  181. while($my_post -> have_posts()): $my_post -> the_post();
  182.  
  183. $values = get_field('diagonostic');
  184. $field = get_field_object('diagonostic');
  185. $choices = $field['choices'];
  186. foreach ($choices as $value => $label) {
  187. echo '<option value="' . $value . '">' . $label. '</option>';
  188.  
  189. }
  190.  
  191. ?>
  192. <?php endwhile; endif; wp_reset_query(); ?>
  193.  
  194. // display random display with ACF repeater content
  195.    
  196. <?php $testimonial = get_field( 'testimonial_area' );  ?>
  197. <?php if( is_array( $testimonial ) ) { ?>
  198.   <?php $testi = array_rand( $testimonial ); ?>
  199.  
  200.         <div class="testimonial_content fix">
  201.             <div class="testimonial_textquote">
  202.                 <h4><?php echo $testimonial[$testi]['testimonial_quote'];?> </h4>
  203.             </div>
  204.             <div class="testimonial_logoicon">
  205.                 <img src="<?php echo $testimonial[$testi]['testimonial_image'];?> " alt="">
  206.             </div>
  207.             <div class="testimonial_title">
  208.                 <h3><?php echo $testimonial[$testi]['testimonial_name'];?> </h3>
  209.             </div>
  210.             <div class="testimonial_position">
  211.                 <h4><?php echo $testimonial[$testi]['testimonial_position'];?> </h4>
  212.             </div>
  213.         </div> 
  214. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment