Last active
July 11, 2018 21:43
-
-
Save cccamuseme/7883db83755e4eba7f1c84bf162fd2e9 to your computer and use it in GitHub Desktop.
Custom post type slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="bx-wrapper"> | |
<ul class="bxslider"> | |
<?php | |
$slider = new WP_Query(array( 'post_type' => 'homepage_slider' ) ); | |
if( $slider->have_posts() ) : | |
while($slider->have_posts()) : | |
$slider->the_post(); | |
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?> | |
<li class="featured-image" style="background-image: url('<?php echo $thumb['0'];?>')"> | |
<div class="slide-wrapper"> | |
<div class="slide-inner"> | |
<?php the_content() ?> | |
</div> | |
</div> | |
</li> | |
<?php | |
endwhile; | |
endif; | |
wp_reset_postdata(); | |
?> | |
</ul><!-- /.bxslider --> | |
</div><!-- /.bx-wrapper --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would discourage the use of both
query_posts()
andwp_rest_query()
as they are considered bad practice. Use thenew WP_Query()
withwp_reset_postdata()
.Here's what the ammended code would look like... Revised CPT Slider