自定义帖子类型分页,如“上一页/当前页/下页”

时间:2011-10-31 作者:Alexey

我有自定义的帖子类型works 使用自定义分类法work_category我想在查看时建立这样的分页single.php

previous 2/25 next

[link to previous post in custom tax] [current post number]/[all post number from custom tax] [next post in custom tax]

目前我无法获取current post number

1 个回复
最合适的回答,由SO网友:Alexey 整理而成

我已经解决了

供上一次/下次使用Ambrosite Next/Previous Post Link Plus

要获取当前/全部,请在循环中使用以下代码

        $query = new WP_Query( array(
            \'post_type\' => \'works\',
            \'post_status\' => \'publish\',
            \'posts_per_page\' => \'-1\',
            \'tax_query\' => array(
                    array(
                        \'taxonomy\' => \'work_category\',
                        \'field\' => \'slug\',
                        \'terms\' => \'design\'
                    )
            ),
            \'order\' => \'ASC\'
        ) );
        $all = $query->post_count;
        foreach( $query->posts as $key => $p )
            if( $post->ID == $p->ID ) $current = $key + 1;

        echo $current.\'/\'.$all;

结束

相关推荐

Broken category pagination

出于某种原因,下面的代码一直工作到我到达第三页并给出404。不使用任何插件就可以修复它吗?<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(\'cat=\'. $id .\'&posts_per_page=4&paged=\'.$paged); while ($wp_query->have_posts()) : $wp_query