WordPress自定义帖子类型分页由$ _GET param

时间:2012-01-20 12:05:05

标签: wordpress pagination permalinks custom-post-type

我有一个页面,我想为某个名为'article'的自定义帖子类型添加分页,我还使用名为'week'的$ _GET参数。

基本上,当我去http://www.mydomain.com/single-page/?week=7时,我希望看到我的帖子从“文章”帖子类型中分页,其分类称为星期等于7。

一切都很好,但是paginate_links功能并不能满足我的需求。例如,2分页链接具有此URL http://www.mydomain.com/single-page/?week=7/page/2。但是这个网址不起作用,它会产生404错误。

但是这个网址http://www.mydomain.com/single-page/page/2/?week=7正在发挥作用。那么解决方案是什么?

  1. 当我访问www.mydomain.com/single-page/?week=时,有没有办法告诉Wordpress使用www.mydomain.com/single-page/page/2/ ?week = 7 7 /页/ 2?

  2. 你有自定义帖子类型分页的好教程吗?

  3. 这是我用于分页的代码:

    //The paginate function
    
        function paginate_articles_week()
        {
            global $wp_query, $wp_rewrite;
            $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
            $pagination = array(
                'base' => @add_query_arg('page'),
                'format' => '?page=%#%',
                'total' => $wp_query->max_num_pages,
                'current' => $current,
                'show_all' => true,
                'type' => 'list',
                'prev_text' => '«',
                'next_text' => '»',
            );
            if ($wp_rewrite->using_permalinks())
                $pagination['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');
            if (!empty($wp_query) && $pagination['total'] != 1) {
                $pagination['add_args'] = array('s' => get_query_var('s'));
                echo "<div class='paginate'><strong>Pagini:</strong>" . paginate_links($pagination) . "</div>";
            }
        }
    
    //The page template
    
    global $post;
    
    $week = $_GET['week'];
    $slug = 'week-' . $week . '-month-2';
    
    $paged = 1;
    $postsPerPage = 1;
    
    if (get_query_var('paged')) { $paged = get_query_var('paged'); }
    if (get_query_var('page'))  { $paged = get_query_var('page');  }
    
    $args = array(
        'post_type'=> 'article',
        'paged'    => $paged,
        'posts_per_page' => $postsPerPage,
        'timeline'       => $slug
    );
    
    
    query_posts($args);
    {the loop}
    
    paginate_articles_week();
    

    提前感谢您的答案:)

0 个答案:

没有答案