Flexslider by category.
-
Hi Guys,
I,ve started using Flexslider in my WordPress installation and I want the slider to display images from certain categories. So far I’ve sorted this but it seems that each time I post with a Featured Image the Flexslider picks that one as well.
Here’s my bit of code.
<div class="flexslider"> <ul class="slides"> <?php $category = get_option('category_name'); $args = array( 'numberposts' => 6, 'category' => 'Tappeti','eBay', 'post__in' => $category ); $postQuery = get_posts($args); foreach( $postQuery as $post ) : setup_postdata($post); if ( has_post_thumbnail() ) { ?> <li> <a href="<?php echo get_permalink(); ?>" title="Go to <?php echo the_title(); ?>" rel="bookmark"> <?php the_post_thumbnail('feature-slider'); ?> <p class="flex-caption"><?php the_title(); ?></p></a> </li> <?php } endforeach; ?> </ul> </div>
Which bit of code am I missing not to display all featured images, but only to display from the specified categories?
Thanks in advance,
Cheers.
-
review:
http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameterswhat are you trying to get with:
$category = get_option('category_name');
– ‘post__in’ expects an array of post IDs
I’m not sure….my PHP is crap!
I want to get the images from the two categories ‘tappeti’ and ‘ebay’ and display them. that’s all I want 🙂
What would you suggest?
Thanks.
for example (untested):
<div class="flexslider"> <ul class="slides"> <?php $cat1 = get_term_by('name','Tappeti','category')->term_id; $cat2 = get_term_by('name','eBay','category')->term_id; $args = array( 'numberposts' => 6, 'category__in' => array( $cat1, $cat2 ) ); $postQuery = get_posts($args); foreach( $postQuery as $post ) : setup_postdata($post); if ( has_post_thumbnail() ) { ?> <li> <a href="<?php echo get_permalink(); ?>" title="Go to <?php echo the_title(); ?>" rel="bookmark"> <?php the_post_thumbnail('feature-slider'); ?> <p class="flex-caption"><?php the_title(); ?></p></a> </li> <?php } endforeach; ?> </ul> </div>
WOW!!!! That is SUPER AWESOME!!! Thank you!
The only thing that I could come up with was this 🙂
<div class="flexslider"> <ul class="slides"> <?php // Get all tappeti and ebay category posts. $args = array( 'numberposts' => 6, // Display up to 6 posts. 'category' => '2,3', ); $postQuery = get_posts($args); foreach( $postQuery as $post ) : setup_postdata($post); if ( has_post_thumbnail() ) { ?> <li> <a href="<?php echo get_permalink(); ?>" title="Go to <?php echo the_title(); ?>" rel="bookmark"> <?php the_post_thumbnail('feature-slider'); ?> p class="flex-caption"><?php the_title(); ?></p></a> </li> <?php } endforeach; ?> </ul> </div>
Looks like it works the same. But I’m sure my bit of code is pretty basic and useless. Could you point out if there are any errors.
Thanks.
- The topic ‘Flexslider by category.’ is closed to new replies.