Support » Fixing WordPress » Loop offset by 1

  • I have a page , News Page, that has a featured article on top, with all other articles(posts) displayed below. The featured article and the first article below are the same. I need the first article below to be offset by 1 so the featured article is not displayed twice. I have tried a query to offset by 1, but the following pages display the same articles as the first page.

    My Code:

    <?php
    /*
    Template Name: News Page
    */
    get_header(); ?>
    
    <div class="container">
      <div class="row">
        <h2 class="page_title">Our Latest News</h2>
        <hr class="fade_rule">
      </div>
    </div>
    <div class="container">
      <div class="row"> </div>
    
      <!--#######################################################################################-->
    
      <?php if( !is_paged() )  {?>
      <div class="news_main news_feed">
        <?php $the_query = new WP_Query( 'showposts=1' ); ?>
        <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
        <a href="<?php the_permalink(); ?>">
        <div class="news_feature_thumb">
          <?php
    					if ( has_post_thumbnail() )
    						the_post_thumbnail( 'full' );
    					else
    
    					?>
        </div>
        <div class="news_featured_content">
          <h3 class="feature-title">
            <?php the_title(); ?>
          </h3>
          <p class="news_date">Date posted:
            <?php the_date(); ?>
          </p>
          <?php echo get_news_excerpt(); ?> </div>
        <div class="clear"></div>
        </a> </div>
      <?php endwhile;?>
      <br />
      <?php } else ?>
    
      <!--#######################################################################################-->
    
      <div id="content" class="js-masonry" data-masonry-options='{ "itemSelector": ".news_item" }'>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="col-4 news_feed_element news_feed news_item"> <a href="<?php the_permalink(); ?>">
          <div class="news_post_thumb">
            <?php
                    if ( has_post_thumbnail() )
                        the_post_thumbnail( 'full' );
                    else
    
                    ?>
          </div>
          <div class="news_feed_content">
            <h3 class="feature-title">
              <?php the_title(); ?>
            </h3>
            <p class="news_date">Date posted:
              <?php the_date(); ?>
            </p>
            <?php echo get_news_excerpt(); ?> </div>
          <div class="clear"></div>
          </a> </div>
        <?php endwhile;?>
      </div>
      <div class="clear"></div>
    </div>
    <div class="navigation" style="width: 100%; text-align:center; margin:0 auto;">
      <p>
        <?php posts_nav_link(); ?>
      </p>
    </div>
    <?php else : ?>
    <h2>Not Found</h2>
    <?php endif; ?>
    </div>
    <?php get_footer(); ?>

    Any suggestions will be welcomed.

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • ‘offset’ breaks the pagination as you have already noticed;
    try working with ‘post__not_in’ and use the post id of the first post;

    see Codex http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

    or search the forum for ‘formatting the first post different’ or similar.

    btw:
    is that really the code of the used template?
    your code does not provide a list of posts after the first one – it simply outputs the content of the page.
    I would assume you need to create a query for all the other posts(?)

    Thread Starter GaryKay

    (@garykay)

    Hi alchymyth,

    Thank you for your reply. That is the code, it works as you can see, but from your comment it seems wrong.

    I have tried ‘post__not_in’ method , I found it here. I will go study the codex.

    Thank you.

    Apologies if I’m using this forum incorrectly. This is my first try. I’m new at this and truing to use the Masonry Widget on my page and need to offset a post so it doesn’t repeat. I notice there’s a place in the widget to put “additional” stuff. I think this is for additional queire arguments. I wonder if there is something I can paste in there that will tell the widget to offset a certain number of posts. I don’t know where to look to find the code for the widget. I assume that would be functions?

    @rwandawire

    please have a look through http://codex.wordpress.org/Forum_Welcome

    and then please start your own topic http://wordpress.org/support/forum/how-to-and-troubleshooting#postform

    use the Masonry Widget

    if you are referring to a plugin, please post in the plugin’s direct support section.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Loop offset by 1’ is closed to new replies.