• I want the first post on the homepage to be different than the rest. I searched the internet and tried MANY code snippets, and finally got the following to work…

    <!-- START Top Post -->
     <?php $top_query = new WP_Query('showposts=1'); ?>
    <?php while($top_query->have_posts()) : $top_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    
    <p>FIRST</p>
    <div class="post-content">
    	<?php $post_excerpt = of_get_option('post_excerpt'); ?>
    	<?php if ($post_excerpt=='true' || $post_excerpt=='') { ?>
    	<?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,23);?>
    	<?php } ?>
    	<a>" class="button"><?php _e('Read more', 'dirtygirl'); ?></a>
    </div>
    
    <?php endwhile; ?>
     <!-- END Top Post -->
    
     <!-- START Other Posts -->
    <?php $top_query = new WP_Query('showposts=7&offset=1'); ?>
    <?php while($top_query->have_posts()) : $top_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    
          <article id="post-<?php the_ID(); ?>" <?php post_class('post-holder'); ?>>
            <div class="inner">
    
            <?php $post_image_size = of_get_option('post_image_size'); ?>
    				<?php if($post_image_size=='' || $post_image_size=='normal'){ ?>
              <?php if(has_post_thumbnail()) {
                echo '<figure class="featured-thumbnail"><span class="img-wrap"><a href="'; the_permalink(); echo '">';
                echo the_post_thumbnail();
                echo '</a></span></figure>';
                }
              ?>
            <?php } else { ?>
              <?php if(has_post_thumbnail()) {
                echo '<figure class="featured-thumbnail large"><span class="img-wrap clearfix"><span class="f-thumb-wrap"><a href="'; the_permalink(); echo '">';
                echo the_post_thumbnail('post-thumbnail-xl');
                echo '</a></span></span></figure>';
                }
              ?>
            <?php } ?>
    
    	   <div class="extra-wrap">
    
    	   	<header class="entry-header">
              <h2><a>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
              <?php $post_meta = of_get_option('post_meta'); ?>
    					<?php if ($post_meta=='true' || $post_meta=='') { ?>
                <div class="post-meta">
                  <div class="fleft"><time datetime="<?php the_time('Y-m-d\TH:i'); ?>"><?php the_time('d-j-Y'); ?></time> <?php comments_popup_link('0', '1', '%', 'comments-link', 'Comments are closed'); ?></div>
                </div><!--.post-meta-->
              <?php } ?>
            </header>
    
            <div class="post-content">
              <?php $post_excerpt = of_get_option('post_excerpt'); ?>
          		<?php if ($post_excerpt=='true' || $post_excerpt=='') { ?>
                <div class="excerpt"><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,23);?></div>
              <?php } ?>
              <a>" class="button"><?php _e('Read more', 'dirtygirl'); ?></a>
            </div>
    
    	   </div>
    	   </div>
          </article>
    
    <?php endwhile; ?>
     <!-- END Other Posts -->

    The problem is that I can no longer get past the first page. If I click on page 2, the URL changes, but the content doesn’t (i.e., the EXACT SAME posts show on all pages).

    Can someone please take a look at my code and tell me what I’m doing wrong?

    Thank you so much for your help!

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still – use the pastebin. As it stands, your code may now have been permanently dmaged/corrupted by the forum’s parser.]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    You can’t use offset with pagination. Try doing it with one loop like this (very simplified example):

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('posts_per_page=8&paged='.$paged); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php if($wp_query->current_post == 0) : ?>
    <!-- do stuff for the first post -->
    <?php else : ?>
    <!-- do stuff for the rest of the posts -->
    <?php endif; ?>
    <?php endwhile; ?>

    Thread Starter idesign123

    (@idesign123)

    Hey, that worked great!

    The only tweak I want to make is to have the top post different ONLY on the first page.

    A search gave me the following code snippet…
    <?php if($i == 0 && $paged == 0):?>

    Could that perhaps be combined with your code somehow?
    Or another way to make the top post different only on the first page?

    Moderator keesiemeijer

    (@keesiemeijer)

    Try changing this:

    <?php if($wp_query->current_post == 0) : ?>

    to this:

    <?php if(!is_paged() && ($wp_query->current_post == 0)) : ?>

    Thread Starter idesign123

    (@idesign123)

    PERFECT!!!

    Thank you so much for your help!

    P.S. The “dirtygirl” references in the code refer to a female gardening website (if you were wondering 😉

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. I’m glad you got it resolved 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘First Post Different – almost there…’ is closed to new replies.