0

Recently I made a theme for my WordPress blog. Now I want to filter(remove) my 5 latest post from the main page (index.php) and show them in a slider. Now my 5 latest posts are showing in the first page and slider simultaneously :(

Update:

Thanks for your reply. I couldn't solve my problem. this is my index.php source:

<?php get_header() ?>

<div id="main-wrapper">
    <div class="middle-content">
        <div id="sidebar-right">
            <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-right')) : else : ?>
            <?php endif; ?>
        </div>
        <section class="clearfix" id="content">
            <section id="main-content">
                <?php echo get_touchcarousel(2); ?>
                <div class="mainnews"><h2>Latest News</h2></div>
                <div class="main-menu-content">
                    <?php if(have_posts()) : ?>
                        <?php while (have_posts()) : the_post(); ?>
                            <article id="etc" class="post<?php the_category_unlinked(' '); ?>">
                                <div class="post-content">
                                    <div class="post-title">
                                        <a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
                                    </div>
                                    <div class="clear"></div>
                                    <?php the_excerpt(); ?>
                                    <?php the_post_thumbnail(array(260,140), array ()); ?>
                                </div>
                                <div class="clear"></div>
                            </article>

                        <?php endwhile; ?>
                    <?php endif; ?>
                </div>
                <?php if(function_exists('wp_simple_pagination')) {
                    wp_simple_pagination();
                } ?>
            </section> 
            <div id="sidebar-left">
                <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-left')) : else : ?>
                <?php endif; ?>
            </div>
        </section>
    </div>
    <div class="clear"></div>
    <?php get_footer(); ?>
</div>
</section>
</div>
<div class="clear"></div>
<?php get_footer(); ?>

Would you please help me?

  • can you provide the code of the first page template? is the slider code in the same template as the loop? – Michael Dec 7 '12 at 11:31
  • You probably need to add wp_reset_postdata() or wp_reset_query() at the end of your loop. – RRikesh Dec 7 '12 at 12:24
0

I don't know if WP has a built in feature for it's query but you could do something like this:

$count = 0;
if(have_posts()) : while (have_posts()) : the_post();
if ($count < 4 ) { $count++; }
else { ... your blogroll code ... } 
endwhile; endif;
|improve this answer|||||
0

As @getglad says you could build in a counter to skip the first returned posts, but it would be better to loop through a separate query like this:

// show ten posts, begin with the fifth
$the_query = new WP_Query( array( 'posts_per_page' => 10, 'offset' => 5 ) );

if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<article>' ... your stuff ... '</article>';
        }
    /* Restore original Post Data */
    wp_reset_postdata();
    }
else {
    // no posts found
    }
|improve this answer|||||
-1

Please check whether you have added wp_reset_query() while ending the loop. Moreover, you can also check whether you have added offset attribute properly to your query_posts.

|improve this answer|||||

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.