获取所有自定义帖子类型:
$post_types = get_post_types( array ( \'_builtin\' => FALSE ), \'objects\' );
按名称排序:
uasort( $post_types, \'sort_cpts_by_label\' );
/**
* Sort post types by their display label.
*
* @param object $cpt1
* @param object $cpt2
* @return int
*/
function sort_cpts_by_label( $cpt1, $cpt2 ) {
return strcasecmp(
$cpt1->labels->name,
$cpt2->labels->name
);
}
如果存档文件确实可用,请将帖子类型名称链接到其存档文件:
foreach ( $post_types as $post_type => $properties ) {
if ( $properties->has_archive ) {
printf(
\'<a href="%1$s">%2$s</a><br>\',
get_post_type_archive_link( $post_type ),
$properties->labels->name
);
}
}