3

I'm trying to set up a wordpress blog. I have one loop with featured posts, that pulls from the 'Featured' category and displays a slider of prominent posts.

Below that, I have the regular feed of posts. The regular feed works great, but the featured posts only show posts from wherever the bottom loop happens to be. Example, if I am on page one of the main feed, the top slider will only show posts with the category featured that are also on page one.

How can I make my slider loop pull from ALL Featured category posts?

EDIT: Added code, below:

<?php
/** Homepage file */
get_header(); ?>
<div id="rotator-wrapper">
<div class="featured-rotator">
    <?php if ( have_posts() ): ?><ul>
        <?php while ( have_posts() ) : the_post(); ?>
        <?php if ( in_category('featured') ): ?>
                <li class="post">
                    <div class="image"><?php the_post_thumbnail(); ?></div>
                    <h2><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <?php if (get_post_meta($post->ID, "Author", true)): ?>
                    <span class="author">By <?php echo get_post_meta($post->ID, "Author", true); ?></span>
                    <?php endif; ?>
                    <?php the_content(__("Continue reading &raquo;")); ?>
                </li>
        <?php endif; ?>
        <?php endwhile; ?>
    </ul><?php endif; ?>
</div>
</div>

<div id="content-wrapper">
    <h2 class="recent">Recent Reviews</h2>
    <?php if ( have_posts() ): ?>   
    <ol>
    <?php while ( have_posts() ) : the_post(); ?>
        <li class="post">
            <article class="post-excerpt">
                <div class="image"><?php the_post_thumbnail(); ?></div>
                <div class="post-meta">
                    <h2 class="post-title"><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <?php if (get_post_meta($post->ID, "Author", true)): ?>
                        <span class="author">By <?php echo get_post_meta($post->ID, "Author", true); ?></span>
                    <?php endif; ?>
                </div><!--post-meta-->
                <?php the_content(__("Continue reading &raquo;")); ?>
            </article>
        </li>
    <?php endwhile; ?>
    </ol>

<nav class="oldernewer cf">
            <div class="newer"><?php previous_posts_link('Newer Entries &raquo;') ?></div><!--.newer-->
            <div class="older"><?php next_posts_link('&laquo; Older Entries ') ?></div><!--.older-->
</nav><!--.oldernewer-->

    <?php else: ?>
    <h2>No posts to display</h2>
    <?php endif; ?>
</div>
<?php get_footer(); ?>
  • 1
    Can ya paste the code for the featured slider post loop? – TomHarrigan May 26 '14 at 3:13
  • Please add all relevant code and information to your question. It is impossible to help you without seeing your code – Pieter Goosen May 26 '14 at 4:33
  • You don't need the first loop, all you need is a slider which pulls your posts and includes settings which enable you to determine which posts featured images are displayed. Choose a new slider. – Brad Dalton May 26 '14 at 4:48
  • @TomHarrigan: added. – authorandrew May 26 '14 at 14:38
  • @BradDalton: I'm not using a plugin slider, I'm building my own using Unslider. – authorandrew May 26 '14 at 14:39
1

Create a new WP_Query for the slider posts.

<div class="featured-rotator">
    <?php $slide_query = new WP_Query( 'category_name=featured' );
          if ( $slide_query->have_posts() ): ?><ul>
        <?php while ( $slide_query->have_posts() ) : $slide_query->the_post(); ?>
                <li class="post">
                    <div class="image"><?php the_post_thumbnail(); ?></div>
                    <h2><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <?php if (get_post_meta($post->ID, "Author", true)): ?>
                    <span class="author">By <?php echo get_post_meta($post->ID, "Author", true); ?></span>
                    <?php endif; ?>
                    <?php the_content(__("Continue reading &raquo;")); ?>
                </li>
        <?php endwhile; ?>
    </ul><?php endif; wp_reset_postdata(); ?>
</div>
  • Works like a charm! I found the codex docs on Wp_query but I couldn't get it to work on my own. Looks like my difference was what I was setting the query to. Thanks for your help! – authorandrew May 26 '14 at 16:37
  • @authorandrew sure thing, glad it helped :) – TomHarrigan May 26 '14 at 16:37

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.