【问题标题】:Wordpress: Use Pagination with showing child pagesWordpress:使用分页显示子页面
【发布时间】:2014-05-02 02:54:55
【问题描述】:

以下是我当前用于在父页面上显示子页面的代码。这段代码工作得很好,但是它在一页上查询所有 240 多个子页面。我想将其限制为每页 20 个,并像帖子一样添加分页。这可能吗?另请注意,我使用的是 'number' => 62,由于某种原因,它会在页面上查询回 15。我可以忍受这个。

$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'menu_order', 'sort_order' => 'asc' , 'number' => 62 ) );

    foreach( $mypages as $page ) {
        $content = $page->post_content;
        if ( ! $content ) // Check for empty page
            continue;

        $content = apply_filters( 'the_content', $content );

然后我调用页面缩略图、页面标题和 2 个 post_meta(自定义字段)查询。

php echo get_page_link( $page->ID ); ?>"><?php echo get_the_post_thumbnail($page->ID, 'thumbnail');

php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title;

$key="Type"; echo get_post_meta($page->ID, $key, true);

echo get_the_term_list( $page->ID, 'areas', '', ', ', '' );

我可以在 $mypages = get_pages 之前使用类似的东西吗?

$page_num = (get_query_var('paged')) ? get_query_var('paged') : 1;

【问题讨论】:

    标签: wordpress pagination parent-child


    【解决方案1】:

    我可以使用

    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
    

    在我的查询中获取页面以显示分页视图。最终查询看起来像这样。希望这可以帮助某人。

    $args = array(
    
            'meta_key' => 'surname',
            'post_type' => 'page',
            'post_status' => 'publish',
            'orderby' => 'meta_value',
            'order' => 'ASC',
            'posts_per_page' => '20',
            'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    );  
    
    query_posts( $args );
    
    if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post();
    

    【讨论】:

      猜你喜欢
      • 2015-06-10
      • 1970-01-01
      • 2015-01-17
      • 2014-03-17
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多