Last active
February 4, 2016 07:03
-
-
Save javierarcheni/fb328fac27d4bd55acb6 to your computer and use it in GitHub Desktop.
Mostrar Custom Post Types en el escritorio de WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'dashboard_glance_items', 'mostrar_cpt_escritorio', 10, 1 ); | |
function mostrar_cpt_escritorio( $items = array() ) { | |
//indicar el/los custom post types | |
$post_types = array('cursos','proyectos' ); | |
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 ) ) { | |
$output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>'; | |
echo '<li class="post-count ' . $post_type->name . '-count">' . $output . '</li>'; | |
} else { | |
$output = '<span>' . $text . '</span>'; | |
echo '<li class="post-count ' . $post_type->name . '-count">' . $output . '</li>'; | |
} | |
} | |
} | |
return $items; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment