除了@Rarsts answer之外,一旦您使用存档创建了自定义帖子类型,如以下示例所示:
//* Create product custom post type
add_action( \'init\', \'register_product_custom_post_type\' );
function register_product_custom_post_type() {
register_post_type( \'product\',
array(
\'labels\' => array(
\'name\' => __( \'Product\', \'wpsites\' ),
\'singular_name\' => __( \'Product\', \'wpsites\' ),
),
\'has_archive\' => true,
\'hierarchical\' => true,
\'menu_icon\' => \'dashicons-portfolio\',
\'public\' => true,
\'rewrite\' => array( \'slug\' => \'product\', \'with_front\' => false ),
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'trackbacks\', \'custom-fields\', \'revisions\', \'page-attributes\' ),
\'taxonomies\' => array( \'product-type\' ),
));
}
您还可以使用pre\\u get\\u posts控制该归档。
add_action( \'pre_get_posts\', \'customize_custom_post_type_archive\' );
function customize_custom_post_type_archive( $query ) {
if ( is_post_type_archive(\'product\') && $query->is_main_query() )
$query->set( \'posts_per_page\', \'6\' );
$query->set( \'order\', \'ASC\' );
return $query;
}
然后,您可以将CPT存档链接作为自定义URL添加到菜单中
http://example.com/product/