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/

智能推荐

注意!

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



猜您在找
Wordpress:具有分页的一页中的多个自定义循环 - Wordpress: Multiple Custom Loop in One Page with Pagination 自定义循环中的分页无法正常工作 - Pagination in custom loop not working Wordpress - 分页和自定义数据库查询 - Wordpress - Pagination and Custom Database Query wordpress自定义帖子类型不会显示在菜单页面中 - wordpress custom post type do not show up in menu page 将自定义css添加到wordpress中的页面模板 - Add custom css to a page template in wordpress
智能推荐
 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告