Snippets

Joseph Dickson the_post_thumbnail() Disable Lazy Loading

Created by Joseph Dickson

File wp-query_carousel.php Added

  • Ignore whitespace
  • Hide word diff
+<?php
+// Query Posts of custom post type carousel using Foundation 6's Orbit and Advanced Custom Fields for an optional redirect
+$the_query = new WP_Query(
+
+	array(
+			'post_type' => 'carousel',
+			'orderby' => 'date',
+			'order' => 'DESC',
+			'posts_per_page' => 5,
+		)
+
+);
+
+// The Loop
+if ( $the_query->have_posts() ) {
+?>
+	<div class="orbit" role="region" aria-label="Slideshow" data-orbit data-use-m-u-i="false">
+        <ul class="orbit-container">
+          <button class="orbit-previous show-for-medium" aria-label="previous"><span class="show-for-sr">Previous Slide</span>&#9664;</button>
+          <button class="orbit-next show-for-medium" aria-label="next"><span class="show-for-sr">Next Slide</span>&#9654;</button>
+<?php
+	while ( $the_query->have_posts() ) {
+		$the_query->the_post();
+			echo ' <li class="orbit-slide">
+			            <div>';
+			// check if the post has a Post Thumbnail assigned to it.
+			if ( has_post_thumbnail() ) {
+
+				// check if redirect is set
+				$redirect = get_field('redirect_to_url');
+				if ( '' != $redirect ) {
+					echo '<a href="' . $redirect . '">';
+				}
+					the_post_thumbnail( 'carousel', [ 'class' => 'orbit-image' , 'loading' => false ] );
+
+				if ( '' != $redirect ) {
+					echo '</a>';
+				}
+				$my_excerpt = get_the_post_thumbnail_caption();
+				if ( '' != $my_excerpt ) {
+					echo '<figcaption class="orbit-caption">' . $my_excerpt . '</figcaption>';
+				}
+
+
+			}
+			echo '</div>
+		          </li>';
+			}
+
+			/* Restore original Post Data */
+			wp_reset_postdata();
+?>
+        </ul>
+      </div>
+<?php
+
+
+} else {
+// no posts found
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.