0

无法弄清楚为什么这会突然停止工作。该网站是:http ://www.revival.tv/sermons/topical-messages/

一旦它进入第二页,它只使用存档模板:(不知道为什么这样做,它在去年工作得很好。想知道 Wordpress 更新是否做到了,我们只是注意到了它。

我正在使用以下内容进行分页:

function pagination($pages = '', $range = 2) {  
     $showitems = ($range * 2)+1;  

     global $paged;

     if(empty($paged)) $paged = 1;

     if($pages == '') {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages) {
             $pages = 1;
         }
     }   

     if($pages != 1) {
         echo "<div class='pagination group'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

         for ($i=1; $i <= $pages; $i++) {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
                 echo ($paged == $i)? "<span class='current-page'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
         echo "</div>\n";
     }
}

然后为布道重写:

// Rewrite the Sermon URL
function sermon_rewrite() {
    $cpt = 'sermon';
    $tax = 'series';

    add_rewrite_rule(
        '^'.$cpt.'s/([^/]+)/page/([0-9]+)/?$',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&paged=$matches[2]',
        'top'
    );
    add_rewrite_rule(
        '^'.$cpt.'s/([^/]+)/([^/]+)/?',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&'.$cpt.'=$matches[2]',
        'top'
    );
    add_rewrite_rule(
        '^'.$cpt.'s/([^/]+)/([^/]+)/([^/]+)/?',
        'index.php?post_type='.$cpt.'&'.$tax.'=$matches[1]&'.$tax.'=$matches[2]&'.$cpt.'=$matches[3]',
        'top'
    );
}
add_action('init','sermon_rewrite');

// Update Wordpress with the rewrite
function sermon_link( $link, $post = 0 ) {
    $cpt = 'sermon';
    $tax = 'series';
    $parent = null;

    $terms = get_the_terms($post->ID, $tax);

    if( !$terms ) {
        $child = 'other';
    } else {
        $child_obj = array_pop($terms);
        $parent_obj = get_term_by('id', $child_obj->parent, $tax);
        $child = $child_obj->slug;
        if ( $parent_obj ) {
            $parent = $parent_obj->slug;
        }
    }

    if ( $post->post_type == $cpt && $terms ) {
        return home_url(user_trailingslashit($cpt.'s/'.$parent.'/'.$child.'/'.$post->post_name));
    } else if ( $post->post_type == $cpt && !$terms ) {
        return home_url(user_trailingslashit($cpt.'s/'.$child.'/'.$post->post_name));
    } else {
        return $link;
    }
}
add_filter('post_type_link', 'sermon_link', 1, 3);
4

1 回答 1

0

我想我已经找到了问题(我只是在这里使用您提供的 URL 反复试验)。以下 URL 成功加载第 2 页。

http://www.revival.tv/sermons/topical-messages/page/2/?post_type=sermons

这使我认为只需在之后添加 s 就index.php?post_type='.$cpt可以了。请参阅下面的示例:

add_rewrite_rule(
    '^'.$cpt.'s/([^/]+)/page/([0-9]+)/?$',
    'index.php?post_type='.$cpt.'s&'.$tax.'=$matches[1]&paged=$matches[2]',
    'top'
);
于 2013-11-06T05:39:01.767 回答