Because of the way my templates are structured, I need to pull the first/sticky post from the site outside of the standard loop, just on the homepage. I'm using _s (underscores.me) as a base, so the current loop on the index look like this:
<?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child theme then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php elseif ( current_user_can( 'edit_posts' ) ) : ?> <?php get_template_part( 'no-results', 'index' ); ?> <?php endif; ?>
What do I have to do to query the first post (I'd like to use the same get_template_part construct if possible), on the homepage only, and not have it interfere with counts for paging past the homepage?
Next part of the question; I now want to add a custom query inbetween the separated first post, and the continuation below, that only pulls a few posts in from specific categories. My query doesn't seem to do anything - what's wrong with it? Are those two main loops interferring with it somehow?
<?php $args = array( 'cat' => 6521,//(int) - use category id. 'category_name' => 'featured', 'dossier', 'destacado', ); $featured_posts = new WP_Query( $args ); // The Loop if ( $featured_posts->have_posts() ) : while ( $featured_posts->have_posts() ) : $featured_posts->the_post(); echo '<div style="background-color:#f00;">'; the_title(); echo '</div>'; endwhile; endif; // Reset Post Data wp_reset_postdata(); ?>