I am using the “Types” wordpress plugin for the first time. I created a custom post type, as well as some custom fields.
How do I dynamically call all the custom posts into a Bootstrap carousel, and also display the fields within that loop?
And how do I limit the amount of posts that will cycle through the carousel? Another requirement is that I need to add that necessary Bootstrap ‘active’ class to only the first post.
Here is my first shot, (also note that I have some custom js for creating pagination for the carousel, but that is not an issue (so far!))
<!-- need to limit the entire carousel to displaying the 5 latest posts -->
<div id="myCarousel2" class="carousel">
<div class="carousel-inner2">
<?php $loop = new WP_Query( array( 'post_type' => 'testimonial' ) ); ?>
<div class="item active" data-title=""><!-- the first div needs a class of active, but the others do not -->
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="slide-copy"><?php the_content(); ?></div>
<!-- need to display a custom field or two here -->
<?php endwhile; ?>
</div>
</div>
</div><!-- end myCarousel -->
Here is my second attempt. I got this to work beautifully, except for displaying the custom field values. Any suggestions? It looks like the syntax is correct… Am I missing something basic here?
<?php $the_query = new WP_Query(array(
'post_type' => 'testimonial',
'posts_per_page' => 1
));
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="item active" data-title="">
<div class="slide-copy">
<?php the_content();?>
<span class="byline"><?php echo get_post_meta($post->ID, 'authorinfo', true); ?></span>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php $the_query = new WP_Query(array(
'post_type' => 'testimonial',
'posts_per_page' => 5,
'offset' => 1
));
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="item" data-title="">
<div class="slide-copy">
<?php the_content();?>
<span class="byline"><?php echo get_post_meta($post->ID, 'authorinfo', true); ?></span>
</div>
</div>