Feeding blog posts from a category into Bootstrap (jQuery) Carousel
-
Hi all,
I’m having some trouble getting post feature images and headlines (with links) from one category to display in a jQuery carousel on my blog home page.
I’m a total novice at PHP so I’m just trying to use the WordPress Codex to get the thing to work. Having some real troubles though and would be really grateful if anyone could shove me in the right direction to a tutorial or Codex page that might be able to help.
I’m trying to use this format to bring the posts in:
<ul> <?php global $post; $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
That’s fine, all except the feature images display in a different div to the headlines so I’m not quite sure how to use the above in this scenario (as I said I’m a total PHP novice!). Here is my HTML:
<div id="myCarousel" class="carousel slide"> <div class="row"> <div class="span5 carousel-inner"> <?php $posts_array = get_posts( $args ); ?> <div class="item active"><a href="<?php $permalink = get_permalink( $id ); ?>"></a><?php the_post_thumbnail();?></a></div> <div class="item"><a href="<?php $permalink = get_permalink( $id ); ?>"></a><?php the_post_thumbnail();?></a></div> <div class="item"><a href="<?php $permalink = get_permalink( $id ); ?>"></a><?php the_post_thumbnail();?></a></div> </div> <div class="span3 feature-headlines"> <ul> <li> <h4><a href="<?php get_category_link( $category_id ); ?> "><?php get_the_category( $id ) ?></a> /</h4> <h3><?php the_title(); ?></h3> </li> <li> <h4><a href="<?php get_category_link( $category_id ); ?> "><?php get_the_category( $id ) ?></a> /</h4> <h3><?php the_title(); ?></h3> </li> <li> <h4><a href="<?php get_category_link( $category_id ); ?> "><?php get_the_category( $id ) ?></a> /</h4> <h3><?php the_title(); ?></h3> </li> </ul> </div> <!-- /.feature-headlines --> </div> <!-- /.row --> </div> <!-- /#myCarousel -->
As you can see I’m doing it all wrong and have managed to get myself into a pickle!
All that displays is the image and the headline for just one of the posts and no links or categories!
Please help!
Thank you in advance for any help you can provide.
Cheers,
Chris
- The topic ‘Feeding blog posts from a category into Bootstrap (jQuery) Carousel’ is closed to new replies.