2012-11-15 2 views

답변

0

가끔 때문에 그냥 사용자 정의 query_posts()을 할 경우 퍼머 충돌 때문에 예기치 404 페이지를 얻을 수 있습니다 (또는 어쩌면 대부분의 시간을 잘 모르겠어요) 그리고 당신은 page-slug/page/2, page-slug/page/3에 링크, 페이지 매김을 추가 , page-slug/page/n, 나는 보통 $_GET 매개 변수로 페이지 매김을 설정합니다. 여기

가에 대한 예제 코드입니다 :

<?php 
/* 
    Template Name: Custom Loop Template 
*/ 
get_header(); 

// Set up the paged variable 
$paged = (isset($_GET['pg']) && intval($_GET['pg']) > 0)? intval($_GET['pg']) : 1; 
query_posts(array('post_type' => 'post', 'paged' => $paged, 'posts_per_page' => 1)); 

?> 
<?php if (have_posts()) : ?> 
    <?php while(have_posts()) : the_post(); ?> 
     <div id="post-<?php echo $post->ID; ?>" <?php post_class(); ?>> 
      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
      <div class="post-excerpt"> 
       <?php the_excerpt(); ?> 
      </div> 
     </div> 
    <?php endwhile; ?> 
    <?php if ($wp_query->max_num_pages > 1) : ?> 
     <div class="pagination"> 
      <?php for ($i = 1; $i <= $wp_query->max_num_pages; $i ++) { 
       $link = $i == 1 ? remove_query_arg('pg') : add_query_arg('pg', $i); 
       echo '<a href="' . $link . '"' . ($i == $paged ? ' class="active"' : '') . '>' . $i . '</a>'; 
      } ?> 
     </div> 
    <?php endif ?> 
<?php else : ?> 
    <div class="404 not-found"> 
     <h3>Not Found</h3> 
     <div class="post-excerpt"> 
      <p>Sorry, but there are no more posts here... Please try going back to the <a href="<?php echo remove_query_arg('pg'); ?>">main page</a></p> 
     </div> 
    </div> 
<?php endif; 

// Make sure the default query stays intact 
wp_reset_query(); 

get_footer(); 
?> 

이 사용자 지정 페이지 템플릿을 생성합니다, Custom Loop Template을 불러 페이지 당 1 최신 게시물을 표시합니다. 하단에서 1부터 시작하여 해당 쿼리의 최대 페이지 수까지의 기본 페이지 매김을 갖습니다.

물론 이것은 아주 기본적인 예제 일 뿐이지 만 나머지는 파악하는 것으로 충분합니다.

관련 문제