2014-09-01 4 views
0

나는 이것을 알아 내려고 벽에 머리를 내리려고했지만 해결책을 얻지 못하는 것 같습니다. 0으로 정의 된 오프셋이 있지만 이전 페이지에 대한 +1 오프셋은 오류 페이지로 연결됩니다. 내가 어디로 잘못 가고 있는지 확실하지 않습니다. 어떤 도움을 주시면 감사하겠습니다.깨진 페이지 매기기

여기

내 page.php 파일에서 모든 코드는 ...

<?php 

$offset = $_GET['offset'] ? $_GET['offset'] : 0; 

$page_title = $wp_query->post->post_title; 
$total_posts = wp_count_posts()->publish; 

if ($page_title == "Blog") { 

?> 
<div id="blog_content"> 
<?php 
    if($_GET['message']){ 
     echo "<div style='background-color:#d9ffd1; padding:10px; margin-bottom:20px;'>".stripslashes($_GET["message"])."</div>"; 
    } 
?> 

<?php 
    $post_count = 0; 

    $args = array('numberposts' => 10, 'post_status' => "publish", "offset"=>$offset*10); 
    $myposts = get_posts($args); 
    foreach($myposts as $post) : setup_postdata($post); $post_count++; ?> 

그리고 내 매김을 제공 할 수있는 모든 도움 누군가를 위해 사전에

<div style="font-size:12px;"> 
     <div style="float:left; width:49%;"> 
     <?php 
     the_post(); 

      if ($offset > 0): ?> 
     <a href="<?php the_permalink()?>&offset=<?=$offset-1?>">&larr; Newer Posts</a> 
     <?php endif; ?> 
     </div> 
     <div style="float:right; width:49%; text-align: right;"> 
     <?php 
     $next_post = get_next_post(); 
     if ($total_posts > $post_count + ($offset*10)): ?> 
     <a href="<?php the_permalink()?>&offset=<?=$offset+1?>">Older Posts &rarr;</a> 
     <?php endif; ?> 
     </div> 
     <div style="clear:both;"></div> 
    </div> 

감사를 링크

+2

를 통해 사용자 정의를 설명해야합니다 왜하지 않았다 이 하나를'http : // wordpress.stackexchange.com /'에 게시하십시오. – zipzit

+0

자세한 정보가 필요하면 오류 페이지 란 무엇입니까? 오류 페이지의 URL은 무엇입니까? – Mattigins

+1

오프 주제, http://wordpress.stackexchange.com에 속함. * sidenote : * 왜 같은 HTML에서 작은 따옴표와 큰 따옴표를 사용합니까? – Raptor

답변

1

그게 당신이 달성하려고하는 것에 대해 완전히 명확하지 않지만, 당신이 자세히보고 싶다고 생각합니다. http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination

쿼리에서 하드 코드 된 오프셋을 지정하면 페이지 매김을 계산하고 처리하기 위해 WordPress에서 내부적으로 오프셋을 사용하기 때문에 페이지 번호가 일 수 있습니다.

이 제한을 피하려면 수동으로 페이지 매김을 처리하려면 추가로 코드를 작성해야합니다. 루프 에 추가 페이지가 있는지 여부를 감지 한 다음 현재 페이지에 대해 적절한 오프셋을 동적으로 계산해야합니다.

사용자 정의 페이지 매김을 제어하는 ​​코드는 모두 template.pp 파일이 아닌 functions.php 파일 내에서 발생합니다. 초기 오프셋을 설정하고 페이지 당 게시물 수를 다시 정의 할 수 있습니다. 위의 코덱 링크에 특정 샘플이 표시됩니다.

쿼리를 실행하기 전에 당신은

add_action('pre_get_posts', 'myprefix_query_offset', 1); 

를 통해 작업을 추가 할 예정 당신은, 그냥 호기심

add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2); 
+0

감사합니다. –