Wordpress為顯示子頁面的自定義循環添加分頁

[英]Wordpress add pagination for custom loop that show subpages


I have one page (not an article) with n subpages. In the main page, I need to show max 3 titles of the subpages and insert a pagination for the other.

我有一個頁面(不是文章)有n個子頁面。在主頁面中,我需要顯示子頁面的最多3個標題,並為另一個插入分頁。

How can I do that?

我怎樣才能做到這一點?

This is my simple code now:

這是我現在的簡單代碼:

<?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; ?>

Thanks.

謝謝。

3 个解决方案

#1


3  

I solved by myself, the solution is to use wp_query() to create a new loop insted of using get_pages().

我自己解決了,解決方案是使用wp_query()創建一個使用get_pages()的新循環。

Here the new code for page title and contentwith pagination by Preeti Dua from Avigma Technology:

這里是來自Avigma Technology的Preeti Dua的頁面標題和內容的新代碼:

    <?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>

#2


0  

not sure,

不確定,

but try following plugin

但請嘗試以下插件

http://wordpress.org/extend/plugins/wp-pagenavi/

http://wordpress.org/extend/plugins/wp-pagenavi/

#3


0  

If you'd like to add subPage title, description or even thumbnail in pagination button you can use the ACP free Wordpress plugin: http://wordpress.org/plugins/advanced-content-pagination/

如果您想在分頁按鈕中添加子頁面標題,說明甚至縮略圖,您可以使用ACP免費Wordpress插件:http://wordpress.org/plugins/advanced-content-pagination/


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/12/30/72060735df132ea970b1e020996cc387.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com