2010-04-06 4 views
2

게시물에서 많은 항목이있는 페이지가 있습니다.Wordpress : posts_nav_link() 도움말

한 번에 10 개의 게시물 만 표시하도록 설정했지만 이전/다음 버튼은 실제로 다음 또는 이전 게시물을 표시하지 않습니다. 단지 동일한 게시물을 계속 표시합니다.

function add_shop() { 
    if (is_page('shop') || is_page('7')) { ?> 
    <div id="content"> 
    <div class="post_box"> 
     <div id="column_1"> 
     <div id="shop_wrapper"> 
      <?php query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10'); 

if (have_posts()) : ?> 
      <?php while (have_posts()) : the_post(); ?> 
      <div class="shop_item"> <a href="<?php getCustomField('link_to_project_page'); ?>"><img src="<?php getCustomField('shop_thumbnail_image'); ?>" alt='photo of <?php getCustomField('title'); ?>' class="shop_thumb" /></a> 
      <div class="shop_content"> 
       <h4><a href="<?php getCustomField('link_to_project_page'); ?>"> 
       <?php getCustomField('title'); ?> 
       </a></h4> 
       <?php getCustomField('duration'); ?> 
       <?php getCustomField('paypal_code'); ?> 
      </div> 
      </div> 
      <?php endwhile; ?> 
     </div> 
     <?php posts_nav_link(); ?> 
     </div> 
     <?php else : ?> 
     <h2>Not Found</h2> 
     <p>Sorry, but you are looking for something that isn't here.</p> 
     <?php include (TEMPLATEPATH . "/searchform.php"); ?> 
     <?php endif; ?> 
    </div> 
    </div> 
    <div id="sidebars"> 
    <div id="sidebar_1" class="sidebar"> 
     <ul class="sidebar_list"> 
     <li class="widget"> 
      <div class="widget_box"> 
      <?php dynamic_sidebar(5); ?> 
      </div> 
     </li> 
     </ul> 
    </div> 
    </div> 
    <?php } } 

답변

1

수동 query_posts()를 호출하고, 자신을 보내려고 WordPress의 게시물을 가져 오는 관련된 변수를 덮어 쓰게됩니다 :

여기에 내가 쓴 기능입니다. $paged와 함께 당신은 단지 "페이지"변수를 포함 할 경우, 또는

query_posts($query_string.'&tag=shop&orderby=title&order=ASC&posts_per_page=10'); 

이 포함됩니다 : 당신이 이미 전송하다는 쿼리 문자열을 유지하려면, 당신은 그것을 대체하는 대신에 연결할한다

위의 도움을 바탕으로
query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged='.$paged); 
+0

난 그냥 나는 그것이 클리오 생각 ... 그 시도 하지만 아직 작동하지 않습니다. 오프셋을 설정해야 할지도 모르지만 그 방법에 대해서는 확실하지 않습니다. – redconservatory

+0

음,'$ paged'는 오프셋을 나타내야합니다. 예를 들어 4 페이지를 보았다면'$ paged'의 값은 4가 될 것입니다.이 값을'posts_per_page'와 함께 사용하여 오프셋을 결정해야합니다. 지금 무엇을 얻고 있습니까? 어떤 글입니까? –

2

, 난 그냥 단지는이 작업있어 :

<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; 
      if ($page == 1) { 
       query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged=$page'); 
     } else { 
      $numposts = get_option('posts_per_page'); 

      // work out offset 
      $offset = (($page -1) * $numposts); // i.e. page 2 - 1 = 1 * 10 (10 for the number of posts) 

      query_posts("tag=shop&orderby=title&order=ASC&offset=$offset&paged=$page&showposts=$numposts"); 
      } 



if (have_posts()) : ?>