2011-12-30 11 views
1

私は1ページ(記事ではありません)にn個のサブページがあります。 メインページでは、サブページの最大3タイトルを表示し、他のサブページのページ番号を挿入する必要があります。Wordpressは、サブページを表示するカスタムループのページングを追加します。

どうすればいいですか?

これが今の私の単純なコードです:

<?php 
    $parent_id = 14; //main page id 
    $pages = get_pages(array('sort_column' => 'menu_order', 'numberposts' => 3, 'child_of' => $parent_id)); 
    foreach ($pages as $page) : ?> 
     <div class="item"> 
      <div class="item-title"> 
       <h2><a href="<?php echo get_permalink($page->ID); ?>"><?php echo $page->post_title; ?></a></h2> 
      </div> 
     </div> 
    <?php endforeach; ?> 

感謝。

+0

あなたはほとんどそれを考え出した。しかし、get_pages関数の結果を微調整するには、カスタムクエリを使用して、現在のサブページよりも大きいIDを持つ1つのサブページをフェッチすることをお勧めします。これは '次のリンク'となり、IDを持つサブページになります現在よりも少ないものが「前のリンク」になります。 – Sterex

答えて

3

を以下試してください私は自分自身で解決し、解決策は、新しいループを作成するためにwp_query()を使用することです(get_pagesを使用してのinsted )

ここAvigmaテクノロジーからPreetiヌサドゥアにより、ページタイトルとcontentwithのページネーションのための新しいコード:

<?php 

    // Pagination variable 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    // The Query 
    $the_query = new WP_Query(array('post_parent' => 782, 'post_type' => 'page', 'paged' => $paged)); 

    // The Loop 
    if($the_query->have_posts()) : while($the_query->have_posts()) : $the_query->the_post(); 
    global $post; 
    $thePostID = $post->ID; /* this variabled is used if you need to get custom fields of the subpage */ 
     ?> 
    <div id="side-post-title"> 
     <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
    </div> 

    <div id="side-post-excerpt"> 
       <?php the_excerpt(); ?> 

      <a href="<?php echo get_permalink($page->ID); ?>"> <div id="read-more"> 
         <img src="/wp-content/uploads/2012/10/read-more-btn.png"/></div> </a>               
     </div> 



<?php endwhile; endif; ?> 

<nav class="navigation"> 
    <div style="float:left;"> <?php next_posts_link('Show older', $the_query->max_num_pages) ?></div> 
    <div style="float:right;"> <?php previous_posts_link('Show newer') ?></div> 
</nav> 
関連する問題