2012-02-10 77 views
1

嘿傢伙我使用WordPress的Imbalance2主題,我已經創建了一個新的循環來處理不同的頁面,因爲我有一個類別指向一個頁面,但是頁面上的帖子加載只是重複,因爲我向下滾動頁面。它使用ajax的東西來加載滾動。下面是我對新的循環代碼:WordPress的帖子重複

<?php if (! have_posts()) : ?> 
    <div id="post-0" class="post error404 not-found"> 
     <h1 class="entry-title"><?php _e('Not Found', 'imbalance2'); ?></h1> 
     <div class="entry-content"> 
      <p><?php _e('Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'imbalance2'); ?></p> 
      <?php get_search_form(); ?> 
     </div><!-- .entry-content --> 
    </div><!-- #post-0 --> 
<?php endif; ?> 

<?php $imbalance2_theme_options = get_option('imbalance2_theme_options') ?> 

<div id="boxes"> 
<?php while (have_posts()) : the_post(); ?> 

    <div class="box"> 
     <div class="rel"> 
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a> 
    <?php if ($imbalance2_theme_options['images_only'] == 0): ?> 

      <h1 style="padding-top:8px; padding-bottom:2px;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 
     <?php the_excerpt() ?> 
        <div class="categories" style="padding-top:5px;"><?php 
        $key = 'title'; 
        $themeta = get_post_meta($post->ID, $key, TRUE); 
        if($themeta != '') { 
         echo "<strong>Job Title: </strong>"; 
        echo $themeta; 
        } 
        ?> 
        <br /> 
        <?php 
        $key = 'location'; 
        $themeta = get_post_meta($post->ID, $key, TRUE); 
        if($themeta != '') { 
         echo "<strong>Location: </strong>"; 
        echo $themeta; 
        } 
        ?> 
        </div> 
      <div class="posted"><?php imbalance2_posted_on() ?> <span class="main_separator">/</span> 
       <?php echo comments_popup_link(__('No comments', 'imbalance2'), __('One Comment', 'imbalance2'), __('% Comments', 'imbalance2')); ?> 
      </div> 
    <?php endif ?> 
      <div class="texts"> 
    <?php if ($imbalance2_theme_options['images_only'] == 1): ?> 
       <a class="transparent" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a> 
    <?php endif ?> 
       <div class="abs"> 
    <?php if ($imbalance2_theme_options['images_only'] == 0): ?> 
       <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('homepage-thumb', array('alt' => '', 'title' => '')) ?></a> 
    <?php endif ?> 
<h1 style="padding-top:8px; padding-bottom:2px;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 
     <?php the_excerpt() ?> 
        <div class="categories" style="padding-top:5px;"><?php 
        $key = 'title'; 
        $themeta = get_post_meta($post->ID, $key, TRUE); 
        if($themeta != '') { 
         echo "<strong>Job Title: </strong>"; 
        echo $themeta; 
        } 
        ?> 
        <br /> 
        <?php 
        $key = 'location'; 
        $themeta = get_post_meta($post->ID, $key, TRUE); 
        if($themeta != '') { 
         echo "<strong>Location: </strong>"; 
        echo $themeta; 
        } 
        ?> 
        </div> 
     <?php the_excerpt() ?> 
        <div class="posted"><?php imbalance2_posted_on() ?> <span class="main_separator">/</span> 
        <?php echo comments_popup_link(__('No comments', 'imbalance2'), __('One Comment', 'imbalance2'), __('% Comments', 'imbalance2')); ?> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 

<?php endwhile; ?> 
</div> 

<?php if ($wp_query->max_num_pages > 1) : 
    if ($imbalance2_theme_options['navigation'] == 0) : // Default ?> 

<div class="fetch"> 
    <?php next_posts_link(__('Load more posts', 'imbalance2')); ?> 
</div> 

<script type="text/javascript"> 
// Ajax-fetching "Load more posts" 
$('.fetch a').live('click', function(e) { 
    e.preventDefault(); 
    $(this).addClass('loading').text('Loading...'); 
    $.ajax({ 
     type: "GET", 
     url: $(this).attr('href') + '#boxes', 
     dataType: "html", 
     success: function(out) { 
      result = $(out).find('#boxes .box'); 
      nextlink = $(out).find('.fetch a').attr('href'); 
      $('#boxes').append(result).masonry('appended', result); 
      $('.fetch a').removeClass('loading').text('Load more posts'); 
      if (nextlink != undefined) { 
       $('.fetch a').attr('href', nextlink); 
      } else { 
       $('.fetch').remove(); 
      } 
     } 
    }); 
}); 
</script> 

    <?php elseif ($imbalance2_theme_options['navigation'] == 1) : // Infinite scroll ?> 

<div class="infinitescroll"> 
    <?php next_posts_link(__('Load more posts', 'imbalance2')); ?> 
</div> 

<script type="text/javascript"> 
// Infinite Scroll 
var href = 'first'; 
$(document).ready(function() { 
    $('#boxes').infinitescroll({ 
     navSelector : '.infinitescroll', 
     nextSelector : '.infinitescroll a', 
     itemSelector : '#boxes .box', 
     loadingImg : '<?php echo get_bloginfo('stylesheet_directory') ?>/images/loading.gif', 
     loadingText : 'Loading...', 
     donetext : 'No more pages to load.', 
     debug : false 
    }, function(arrayOfNewElems) { 
     $('#boxes').masonry('appended', $(arrayOfNewElems)); 
     if (href != $('.infinitescroll a').attr('href')) 
     { 
      href = $('.infinitescroll a').attr('href'); 
     } 
    }); 
}); 
</script> 

    <?php endif; ?> 

<?php endif; ?> 

感謝您的幫助, 亞當

回答

1

我認爲它的,因爲你有兩個<?php the_excerpt() ?>裏面一個循環,在54行和73

+0

了看看那個嘗試刪除其中一個,但沒有運氣:( – adamhuxtable 2012-02-10 14:50:58

+0

對不起,我錯過了一個..總共有三個the_excerpt() – tinyhook 2012-02-10 19:29:06

+0

你有在這裏如果陳述'<?php if($ imbalance2_theme_options ['images_only' ] == 0):?>'...從我對你的代碼的理解中,你只需要其中的一個......我有點兒現在沒有時間了,所以我無法給你的代碼一個徹底的看,這意味着我可能是錯誤的以上的東西。 – tinyhook 2012-02-10 19:40:21