GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
views/list/list-body.php
Go to the documentation of this file.
1 <?php
2 /**
3  * The entry loop for the list output.
4  *
5  * @global \GV\Template_Context $gravityview
6  */
7 
8 if ( ! isset( $gravityview ) || empty( $gravityview->template ) ) {
9  gravityview()->log->error( '{file} template loaded without context', array( 'file' => __FILE__ ) );
10  return;
11 }
12 
13 $template = $gravityview->template;
14 
15 /** @action `gravityview/template/list/body/before` */
16 $template::body_before( $gravityview );
17 
18 // There are no entries.
19 if ( ! $gravityview->entries->count() ) {
20 
21  $no_results_css_class = 'gv-no-results gv-no-results-text';
22 
23  if ( 1 === (int) $gravityview->view->settings->get( 'no_entries_options', '0' ) ) {
24  $no_results_css_class = 'gv-no-results gv-no-results-form';
25  }
26 
27  ?>
28  <div class="gv-list-view <?php echo esc_attr( $no_results_css_class ); ?>">
29  <div class="gv-list-view-title">
30  <h3><?php echo gv_no_results( true, $gravityview ); ?></h3>
31  </div>
32  </div>
33  <?php
34 } else {
35  // There are entries. Loop through them.
36  foreach ( $gravityview->entries->all() as $entry ) {
37 
39 
40  /** @filter `gravityview/template/list/entry/class` */
41  $entry_class = $template::entry_class( 'gv-list-view', $entry, $gravityview );
42 
43  ?>
44  <div id="gv_list_<?php echo esc_attr( $entry_slug ); ?>" class="<?php echo gravityview_sanitize_html_class( $entry_class ); ?>">
45 
46  <?php
47 
48  /** @action `gravityview/template/list/entry/before` */
49  $template::entry_before( $entry, $gravityview );
50 
51  /**
52  * @var bool $has_title
53  * @var bool $has_subtitle
54  * @var \GV\Field_Collection $title
55  * @var \GV\Field_Collection $subtitle
56  */
57  extract( $template->extract_zone_vars( array( 'title', 'subtitle' ) ) );
58 
59  if ( $has_title || $has_subtitle ) {
60 
61  /** @action `gravityview/template/list/entry/title/before` */
62  $template::entry_before( $entry, $gravityview, 'title' );
63 
64  ?>
65 
66  <div class="gv-list-view-title">
67  <?php
68  $did_main = 0;
69  foreach ( $title->all() as $i => $field ) {
70  // The first field in the title zone is the main
71  if ( $did_main == 0 ) {
72  $did_main = 1;
73  $extras = array( 'wpautop' => false, 'markup' => '<h3 class="{{ class }}">{{ label }}{{ value }}</h3>' );
74  } else {
75  $extras = array( 'wpautop' => true );
76  }
77 
78  $extras['zone_id'] = 'directory_list-title';
79  echo $gravityview->template->the_field( $field, $entry, $extras );
80  }
81 
82  if ( $has_subtitle ) {
83  ?><div class="gv-list-view-subtitle"><?php
84  $did_main = 0;
85  foreach ( $subtitle->all() as $i => $field ) {
86  // The first field in the subtitle zone is the main
87  if ( $did_main == 0 ) {
88  $did_main = 1;
89  $extras = array( 'markup' => '<h4 id="{{ field_id }}" class="{{ class }}">{{ label }}{{ value }}</h4>' );
90  }
91 
92  $extras['zone_id'] = 'directory_list-subtitle';
93  echo $gravityview->template->the_field( $field, $entry, $extras );
94  }
95  ?></div><?php
96  }
97  ?>
98  </div>
99  <?php
100 
101  /** @action `gravityview/template/list/entry/title/after` */
102  $template::entry_after( $entry, $gravityview, 'title' );
103 
104  }
105 
106  /**
107  * @var bool $has_image
108  * @var bool $has_description
109  * @var bool $has_content_attributes
110  * @var \GV\Field_Collection $image
111  * @var \GV\Field_Collection $description
112  * @var \GV\Field_Collection $attributes
113  */
114  extract( $template->extract_zone_vars( array( 'image', 'description', 'content-attributes' ) ) );
115 
116  $has_content_before_action = has_action( 'gravityview/template/list/entry/content/before' );
117  $has_content_after_action = has_action( 'gravityview/template/list/entry/content/after' );
118 
119  if ( $has_image || $has_description || $has_content_attributes || $has_content_before_action || $has_content_after_action ) {
120  ?>
121  <div class="gv-grid gv-list-view-content">
122 
123  <?php
124 
125  /** @action `gravityview/template/list/entry/content/before` */
126  $template::entry_before( $entry, $gravityview, 'content' );
127 
128  if ( $has_image ) {
129  ?><div class="gv-grid-col-1-3 gv-list-view-content-image"><?php
130  foreach ( $image->all() as $i => $field ) {
131  echo $gravityview->template->the_field( $field, $entry, array( 'zone_id' => 'directory_list-image' ) );
132  }
133  ?></div><?php
134  }
135 
136  if ( $has_description ) {
137  ?><div class="gv-grid-col-2-3 gv-list-view-content-description"><?php
138  foreach ( $description->all() as $i => $field ) {
139  $extras = array( 'wpautop' => true, 'zone_id' => 'directory_list-description', 'label_markup' => '<h4>{{ label }}</h4>' );
140  echo $gravityview->template->the_field( $field, $entry, $extras );
141  }
142  ?></div><?php
143  }
144 
145  if ( $has_content_attributes ) {
146  ?><div class="gv-grid-col-3-3 gv-list-view-content-attributes"><?php
147  foreach ( $attributes->all() as $i => $field ) {
148  $extras = array( 'zone_id' => 'directory_list-content-attributes', 'markup' => '<p id="{{ field_id }}" class="{{ class }}">{{ label }}{{ value }}</p>' );
149  echo $gravityview->template->the_field( $field, $entry, $extras );
150  }
151  ?></div><?php
152  }
153 
154  /** @action `gravityview/template/list/entry/content/after` */
155  $template::entry_after( $entry, $gravityview, 'content' );
156  ?>
157 
158  </div>
159 
160  <?php
161  }
162 
163  /**
164  * @var bool $has_footer_left
165  * @var bool $has_footer_right
166  * @var \GV\Field_Collection $footer_left
167  * @var \GV\Field_Collection $footer_right
168  */
169  extract( $template->extract_zone_vars( array( 'footer-left', 'footer-right' ) ) );
170 
171  // Is the footer configured?
172  if ( $has_footer_left || $has_footer_right ) {
173  /** @action `gravityview/template/list/entry/footer/before` */
174  $template::entry_before( $entry, $gravityview, 'footer' );
175  ?>
176 
177  <div class="gv-grid gv-list-view-footer">
178  <div class="gv-grid-col-1-2 gv-left">
179  <?php
180  foreach ( $footer_left->all() as $i => $field ) {
181  echo $gravityview->template->the_field( $field, $entry, array( 'zone_id' => 'directory_list-footer-left' ) );
182  }
183  ?>
184  </div>
185 
186  <div class="gv-grid-col-1-2 gv-right">
187  <?php
188  foreach ( $footer_right->all() as $i => $field ) {
189  echo $gravityview->template->the_field( $field, $entry, array( 'zone_id' => 'directory_list-footer-right' ) );
190  }
191  ?>
192  </div>
193  </div>
194 
195  <?php
196 
197  /** @action `gravityview/template/list/entry/footer/after` */
198  $template::entry_after( $entry, $gravityview, 'footer' );
199 
200  } // End if footer is configured
201 
202  /** @action `gravityview/template/list/entry/after` */
203  $template::entry_after( $entry, $gravityview );
204 
205  ?>
206 
207  </div>
208 
209  <?php }
210 }
211 
212 /** @action `gravityview/template/list/body/after` */
213 $template::body_after( $gravityview );
$image
Definition: post_image.php:98
gv_no_results( $wpautop=true, $context=null)
Definition: class-api.php:942
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
static get_entry_slug( $id_or_string, $entry=array())
Get the entry slug for the entry.
Definition: class-api.php:550
gravityview()
The main GravityView wrapper function.
$entry_slug
Definition: notes.php:30
$entry
Definition: notes.php:27
$description
Definition: post_image.php:28
$title