2013-10-20 2 views
0

저는 wordpress에서 월간 아카이브를 구현 중이며, date.php 파일을 사용하여 한 달에 게시물을 표시하고 있습니다. 이 파일에서 나는 페이징 코드를 가지고 달과 날짜를 얻을 수 있지만 루프는 5 개의 게시물 만 표시하고 빈 포스트가 많이 포함됩니다. 페이징을하면 페이지 당 3 개의 포스트가 있고 총 페이지는 5 개입니다. 페이징 작업. 이 외에도 결과에는 빈 게시물이 많이 포함되어 있습니다 (즉, 필드가없는 것을 의미하지만 the_title은 1979 년 1 월 1 일을 반환합니다). 페이징 로직을 포함Wordpress Date.php는 5 개의 게시물과 많은 빈 게시물을 반환합니다.

$current_page = max(1, get_query_var('paged')); 
$posts = get_posts('cat=19,20&posts_per_page=3&monthnum='.$m.'&year='.$y.'&paged='.$current_page); 
    if (have_posts()) { 
     while (have_posts()) { 
      the_post(); 
      // 
      // Post Content here 
      ?> 

<?php $externalLink = do_shortcode('[cft key=external before_list="" after_list="" before_value="" after_value=""]'); ?> 
<?php if(strlen($externalLink) <= 1): ?> 
          <div class="title"> 
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
          <div class="time small"> 
          <?php if(get_the_time('Y') != '1970') the_time('F jS, Y'); //the_category('','multiple'); ?> 
          </div> 
          </div> 
<?php else: ?> 
          <div class="title"> 
          <a href="<?php echo $externalLink ?>" target="_blank" rel="bookmark" title="External Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
          <div class="time small"> 
          <?php if(get_the_time('Y') != '1970') the_time('F jS, Y'); // the_category('','multiple');?> 
          </div> 
          </div> 
<?php endif; ?>    

<?php 
     } // end while 
    } // end if 
?> 

전체 코드는 여기있다 : https://gist.github.com/uansett/fd1183216ab980e1279a#file-date-php

을 - (전체 게시물을 외부에 저장되어있는 경우의 사용자 정의 필드를 결정하기 위해 신경 끄시 외부 비트)

내 루프는 다음과 같습니다

답변

1

get_posts은 WordPress가 페이지에 대해 이미 선택한 게시물을 대체하지 않습니다. 당신이 워드 프레스가 선택한 게시물을 교체 않는, query_posts를 사용할 수

$posts = get_posts('cat=19,20&posts_per_page=3&monthnum='.$m.'&year='.$y.'&paged='.$current_page); 
foreach ($posts as $post) : setup_postdata($post); ?> 
    // Your code 
<?php endforeach; 
wp_reset_postdata(); // If you still want to access the originally selected posts ?> 

실패 : 당신은 (테스트되지 않은) 같은 것을 필요 했어. 코덱스는 일반적으로 query_posts을 사용하지 말 것을 권고하지만,

TL; DR은 query_posts()를 사용하지 않습니다.

+0

우수함,이 점이 저를 위해 해결되었습니다. 이제 더 이상 빈 게시물이 없습니다. 건배 – Alex