0

I'm trying to set up a slider with the most recent posts from a certain category, but I can't seem to get it to work.

When I use the regular loop, the slider works just fine, but as soon as I add the new query for the specific category, the slider won't work anymore - even though the query seems to be working just fine, since I can see other posts - they're just static and not sliding.

I'm using carouFredSel for the slider, and this is my code:

<div class="wrapper">
    <div class="list_carousel responsive">
        <ul id="desliza">
            <?php $catquery = new WP_Query( 'cat=19' ); while($catquery->have_posts()) : $catquery->the_post(); ?>
                <li>
                    <div class="feattitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title() ;?></a></div>
                    <?php if ( has_post_thumbnail() ) {the_post_thumbnail('destaque', array( 'itemprop' => "image"));} else { ?>
                        <img src="<?php bloginfo('template_directory'); ?>/images/base-thumb.png" alt="<?php the_title(); ?>" />
                    <?php } ?>
                </li>
            <?php endwhile; ?>
        </ul>
    </div>
</div>

Alternative query I've tried:

<?php query_posts( 'cat=19' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

(And a couple other variations of this.)

What's the issue, and how can I get the slider to display just one specific category?

1 Answer 1

1

For this example I used a fake category called "Slider Category" you will need to create that or replace that section of the code.

<? $query = new WP_Query( array( 'category_name' => 'Slider Category' ) ); ?>

   <div class="wrapper">
    <div class="list_carousel responsive">
        <ul id="desliza">
            <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
                <li>
                    <div class="feattitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title() ;?></a></div>
                    <?php if ( has_post_thumbnail() ) {the_post_thumbnail('destaque', array( 'itemprop' => "image"));} else { ?>
                        <img src="<?php bloginfo('template_directory'); ?>/images/base-thumb.png" alt="<?php the_title(); ?>" />
                    <?php } ?>
                </li>
            <?php endwhile; ?>
        </ul>
    </div>
</div>
4
  • May you please elaborate your answer? Just posting code doesn't help explain how it will solve the question. Sep 19, 2016 at 5:21
  • I updated the code Sep 19, 2016 at 5:29
  • can you please up vote my solution? thanks Sep 19, 2016 at 6:51
  • It didn't solve the problem. It displays the posts from the right category - just like the other codes did - but the slider still won't work.
    – Gabrielle
    Sep 19, 2016 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.