我发现以下代码片段将显示在仪表板的“概览”小部件中发布的自定义帖子类型的数量,如下所示:
有没有一种方法可以将“ 81 Wrestlers”文本变成指向帖子类型列表的链接。这是代码:
add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 );
function custom_glance_items( $items = array() ) {
$post_types = array( 'wrestler' );
foreach( $post_types as $type ) {
if( ! post_type_exists( $type ) ) continue;
$num_posts = wp_count_posts( $type );
if( $num_posts ) {
$published = intval( $num_posts->publish );
$post_type = get_post_type_object( $type );
$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'your_textdomain' );
$text = sprintf( $text, number_format_i18n( $published ) );
if ( current_user_can( $post_type->cap->edit_posts ) ) {
$items[] = sprintf( '%2$s', $type, $text ) . "\n";
} else {
$items[] = sprintf( '%2$s', $type, $text ) . "\n";
}
}
}
return $items;
}