0

I have a carousel that I want to be posted on the front page only but for some reason the code is not working.

The conditional statement

<?php if ( is_home() ) : ?>

    <div class="hero">
        <div class="hero-carousel">

            <?php
                $catquery = new WP_Query( 'category_name=feature&cat=1&posts_per_page=5' );
                while($catquery->have_posts()) : $catquery->the_post();
            ?>

            <article>
                        <?php the_post_thumbnail(); ?>
            </article>

            <?php endwhile; ?>

        </div>
    </div>

<?php endif; ?>
6
  • The site is on modestewebstudio.com/theelement
    – Zenneson
    Commented Mar 29, 2015 at 1:17
  • 5
    What does not working mean? Commented Mar 29, 2015 at 5:55
  • Seems to be your code is working, but I can see that the problem is related to image sizes to meet your jquery; customizing takes a little time. @zenneson Commented Mar 29, 2015 at 7:51
  • Make sure you are using the right conditional codex.wordpress.org/Function_Reference/…
    – Z. Zlatev
    Commented Mar 29, 2015 at 10:30
  • You need to expand your question and provide more information like where the code is and more detail about what you have tried to fix it and why it isn't working. Commented Mar 29, 2015 at 15:21

1 Answer 1

1

The is_home() conditional tag applies to the posts page according to your reading settings or home.php file as opposed to the is_front_page() conditional which applies to the page on front according to your reading settings or your front-page.php file, if it exists.

Try changing is_home() to is_front_page()

As for another possible problem might be, take a look at your query arguments

$catquery = new WP_Query( 'category_name=feature&cat=1&posts_per_page=5' );

You are using category_name and cat together in one argument. You cannot do that. You have to use one or the other. So you either have to remove the category_name parameter or the cat parameter

3
  • 1
    Added my answer to yours. A combination of our answers should do the trick. +1 Commented Mar 29, 2015 at 15:26
  • When I put is_home() the carousel shows on all the post pages. But when I put is_front_page() it doesn't show at all.
    – Zenneson
    Commented Mar 29, 2015 at 17:05
  • 1
    @Zenneson If you only need to display this on page one, change <?php if ( is_home() ) : ?> to <?php if ( is_home() && !is_paged() ) : ?> Commented Mar 30, 2015 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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