【问题标题】:WP - custom post type paginationWP - 自定义帖子类型分页
【发布时间】:2014-04-16 11:48:51
【问题描述】:

我想在 category.php 中使用分页制作循环。我的循环如下所示:

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query( array(
    'post_type' => 'blog',
    'posts_per_page' => 2,
    'orderby'=> 'menu_order',
    'paged' => $paged
    ) );

    while ($wp_query->have_posts()) : $wp_query->the_post(); 
    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
?>

<!-- start article -->

<!-- end article -->

<?php endwhile; ?>

<?php get_template_part('pagination') ?>

和功能:

function pagination()
{
    global $wp_query;
    $big = 999999999;
    echo paginate_links(array(
        'base' => str_replace($big, '%#%', get_pagenum_link($big)),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged')),
        'prev_text'    => __('<i class="fa fa-chevron-left"></i>'),
        'next_text'    => __('<i class="fa fa-chevron-right"></i>'),
        'total' => $wp_query->max_num_pages,
    ));
}

当我点击分页链接时,他将我发送到site/?cat=9&amp;paged=2,这个网站是索引,而不是我的下一页有帖子。试了很多方法,不知道哪里出了问题……

有什么建议吗?

PS。不要想知道为什么我将分页作为 template_part :)

【问题讨论】:

    标签: php wordpress pagination categories custom-post-type


    【解决方案1】:

    完全可以。我查了一下。

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query(array('post_type' =&gt; 'blog','posts_per_page' =&gt; 2,'orderby'=&gt; 'menu_order','paged'=&gt;$paged));
    while ( $wp_query-&gt;have_posts() ) : $wp_query-&gt;the_post();the_title();endwhile;

    对于分页,我在同一页面上使用您的代码。

    $big = 999999999;
        echo paginate_links(array(
            'base' => str_replace($big, '%#%', get_pagenum_link($big)),
            'format' => '?paged=%#%',
            'current' => max(1, get_query_var('paged')),
            'prev_text'    => __(''),
            'next_text'    => __(''),
            'total' => $wp_query->max_num_pages,
    ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 2014-05-15
      相关资源
      最近更新 更多