自定义投递类型分页404

时间:2015-05-24 作者:James

我有一个名为scents\\u list的自定义帖子类型和一个名为scents\\u category的自定义分类法。

我的目标是拥有像domain这样的页面。com/剧集/第一季。这非常有效,如果我有一个名为taxonomy-scents\\u category的模板的话。php和某人进入域。com/剧集/第一季,使用标准WordPress循环,它运行良好,并显示了第一季的所有剧集。

然而,当我尝试将分页添加到此页面时,当有人转到第2页时,url将更改为“域”。com/剧集/第一季/第页/第2页,返回404。我不知道如何让分页工作。

标准循环结束后的分页代码,同时:

next_posts_link( \'Older posts\' );
previous_posts_link( \'Newer posts\' );
我的自定义帖子类型/分类代码如下。

// Register Custom Post Type
function episodes() {

$labels = array(
\'name\'                => _x( \'Episodes\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\'       => _x( \'Episodes\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\'           => __( \'Episodes\', \'text_domain\' ),
\'parent_item_colon\'   => __( \'Parent Item:\', \'text_domain\' ),
\'all_items\'           => __( \'All Episodes\', \'text_domain\' ),
\'view_item\'           => __( \'View Item\', \'text_domain\' ),
\'add_new_item\'        => __( \'Add New Episode\', \'text_domain\' ),
\'add_new\'             => __( \'Add New Episode\', \'text_domain\' ),
\'edit_item\'           => __( \'Edit Item\', \'text_domain\' ),
\'update_item\'         => __( \'Update Item\', \'text_domain\' ),
\'search_items\'        => __( \'Search Item\', \'text_domain\' ),
\'not_found\'           => __( \'Not found\', \'text_domain\' ),
\'not_found_in_trash\'  => __( \'Not found in Trash\', \'text_domain\' )
);
$rewrite = array(
\'slug\'                => \'episodes/%episodes_category%\',
\'with_front\'          => false
);
$args = array(
\'label\'               => __( \'episodes\', \'text_domain\' ),
\'description\'         => __( \'All  episodes\', \'text_domain\' ),
\'labels\'              => $labels,
\'supports\'            => array(\'title\' ),
\'taxonomies\'          => array(\'episodes_category\' , \'post_tag\'),
\'hierarchical\'        => true,
\'public\'              => true,
\'show_ui\'             => true,
\'show_in_menu\'        => true,
\'show_in_nav_menus\'   => true,
\'show_in_admin_bar\'   => true,
\'menu_position\'       => 5,
\'can_export\'          => true,
\'has_archive\'         => \'episodes\',
\'exclude_from_search\' => false,
\'publicly_queryable\'  => true,
\'rewrite\'             => $rewrite,
\'capability_type\'     => \'post\',
\'query_var\'           => true,
    \'menu_icon\' => \'dashicons-media-video\'
);
register_post_type( \'episodes_listing\', $args );

}


function episodes_taxomony() {

    $labels = array(
        \'name\'                       => _x( \'Episodes Categories\', \'Taxonomy General Name\', \'text_domain\' ),
        \'singular_name\'              => _x( \'Episodes\', \'Taxonomy Singular Name\', \'text_domain\' ),
        \'menu_name\'                  => __( \'Episode Categories\', \'text_domain\' ),
        \'all_items\'                  => __( \'All Items\', \'text_domain\' ),
        \'parent_item\'                => __( \'Parent Item\', \'text_domain\' ),
        \'parent_item_colon\'          => __( \'Parent Item:\', \'text_domain\' ),
        \'new_item_name\'              => __( \'New Item Name\', \'text_domain\' ),
        \'add_new_item\'               => __( \'Add new Episode Category\', \'text_domain\' ),
        \'edit_item\'                  => __( \'Edit Item\', \'text_domain\' ),
        \'update_item\'                => __( \'Update Item\', \'text_domain\' ),
        \'separate_items_with_commas\' => __( \'Separate items with commas\', \'text_domain\' ),
        \'search_items\'               => __( \'Search Items\', \'text_domain\' ),
        \'add_or_remove_items\'        => __( \'Add or remove items\', \'text_domain\' ),
        \'choose_from_most_used\'      => __( \'Choose from the most used items\', \'text_domain\' ),
        \'not_found\'                  => __( \'Not Found\', \'text_domain\' )
    );
    $rewrite = array(
        \'slug\'                       => \'episodes\',
        \'with_front\'                 => false,
        \'hierarchical\'               => true

    );
    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => true,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => true,
        \'query_var\'                  => true,
        \'rewrite\'                    => $rewrite
    );
    register_taxonomy( \'episodes_category\', array(\'episodes_listing\'), $args );

}

1 个回复
SO网友:Bruno Monteiro

是否确实没有与自定义帖子类型同名的页面?如果这样做,permalink重写规则将变得混乱,并触发404。

一个非常简单的解决方案是:列出自定义帖子类型的页面以复数形式(例如products)调用,而实际的帖子类型名称以单数形式(例如product)调用。所以他们没有冲突,一切都很好。

还要始终确保重写您的。创建新的自定义帖子类型时使用htaccess文件。

结束

相关推荐

Pagination on Single Post

我想在我的单曲上设置分页。php文件,以便正确使用无限滚动函数。我知道分页可以放在一个帖子上,但我需要做一个。php页面可以在URL上附加一个变量。我的意思是,如果我有这个URL:http://www.example.com/post_URL/ 我需要它像这样工作:http://www.example.com/post_URL/page/2/ 它需要像这样工作,因为我在主页/主博客页面上有一个无限滚动条,它选择的是get\\u query\\u var(\'page\')变量,它似乎不