CPT存档重定向至单个帖子

时间:2019-02-21 作者:labworxsa

好的,标题没有太大帮助,所以让我试着解释一下。

这是一个基于Genesis的网站。

我创建了一个CPT:

function cptui_register_my_cpts_livestreams() {

/**
 * Post Type: live streams.
 */

$labels = array(
    "name" => __( \'Live streams\', \'\' ),
    "singular_name" => __( \'Live stream\', \'\' ),
    "menu_name" => __( \'Live streams\', \'\' ),
    "all_items" => __( \'All live streams\', \'\' ),
    "add_new" => __( \'Add new live stream\', \'\' ),
    "add_new_item" => __( \'Add new live stream\', \'\' ),
    "edit_item" => __( \'Edit live stream\', \'\' ),
    "view_item" => __( \'New live stream\', \'\' ),
    "view_items" => __( \'View live streams\', \'\' ),
    "search_items" => __( \'Search live streams\', \'\' ),
    "archives" => __( \'Live streams\', \'\' ),
);

$args = array(
    "label" => __( \'Live streams\', \'\' ),
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "publicly_queryable" => true,
    "show_ui" => true,
    "show_in_rest" => false,
    "rest_base" => "",
    "has_archive" => true,
    "show_in_menu" => true,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "rewrite" => array( "slug" => "live-stream", "with_front" => true ),
    "query_var" => true,
    "supports" => array( "title", "thumbnail", "genesis-cpt-archives-settings", \'genesis-seo\' ),
    \'yarpp_support\' => true,
);

register_post_type( "livestreams", $args );
}

add_action( \'init\', \'cptui_register_my_cpts_livestreams\' );
我还创建了一个文件:archive-livestreams.php

不知什么原因当我去https://inthebunch.co.za/live-stream/ 它会将我重定向到该帖子类型中创建的最新帖子。

我清除了缓存,重新保存了永久链接等。。。有什么建议吗?

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

存档的URL为https://inthebunch.co.za/livestreams/.

看看the docs for register_post_type, 具体来说has_archive 参数:

has_archive (布尔值或字符串)(可选)启用post类型存档<默认情况下,em>将使用$post\\U type作为归档slug。默认值:false

对于您的代码,$post_typelivestreams:

register_post_type( "livestreams", $args );
如果要更改该值,可以为has_archive:

"has_archive" => "live-stream",

相关推荐

Posts feed number of posts

祝大家节日快乐!我希望你能帮我解决这个“小”问题:)我正在使用基于Elara 它以不同的格式在首页和归档页上显示帖子提要。主要区别在于,在首页上,该设计最适合8篇文章,而在存档页上,它最适合导航前的10篇文章。但是,没有指定不同限制的选项。据我所知,饲料是由以下因素控制的:<?php /** * The loop / blog feed * * @package elara */ ?> <div id=\"blog