X

Incluir tipos de entrada personalizados en el widget “Ahora mismo” del panel de control de administración

Snippets by IsItWP

¿Estás buscando una forma de incluir tipos de entrada personalizados en el widget del panel de administración “Ahora mismo”? Si bien es probable que haya un plugin para esto, hemos creado un fragmento de código rápido que puede utilizar para incluir tipos de entradas personalizadas en el widget del panel de administración “Right Now” en WordPress.

Instrucciones:

Todo lo que tienes que hacer es añadir este código al archivo functions.php de tu tema o en un plugin específico del sitio:

function wph_right_now_content_table_end() {
 $args = array(
  'public' => true ,
  '_builtin' => false
 );
 $output = 'object';
 $operator = 'and';

 $post_types = get_post_types( $args , $output , $operator );
 foreach( $post_types as $post_type ) {
  $num_posts = wp_count_posts( $post_type->name );
  $num = number_format_i18n( $num_posts->publish );
  $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
  if ( current_user_can( 'edit_posts' ) ) {
   $num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
   $text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
  }
  echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
  echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
 }
 $taxonomies = get_taxonomies( $args , $output , $operator ); 
 foreach( $taxonomies as $taxonomy ) {
  $num_terms  = wp_count_terms( $taxonomy->name );
  $num = number_format_i18n( $num_terms );
  $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
  if ( current_user_can( 'manage_categories' ) ) {
   $num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
   $text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
  }
  echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
  echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
 }
}
add_action( 'right_now_content_table_end' , 'wph_right_now_content_table_end' );

Nota: Si es la primera vez que añades fragmentos de código en WordPress, consulta nuestra guía sobre cómo añadir correctamente fragmentos de código en WordPress, para no romper accidentalmente tu sitio.

Si te ha gustado este fragmento de código, por favor, considere la posibilidad de revisar nuestros otros artículos en el sitio como: 9 mejores plugins de help desk para WordPress y cómo configurar el seguimiento de descargas en WordPress con Google Analytics.

Comentarios   Deja una respuesta

  1. have anone a fix for wordpress 3.8?

    1. A lot of my dashboard customisations have broken in 3.8.
      Has anyone found a fix that will reinstate the ability to add CPT post counts to the Dashboard?

  2. Thanks for this wonderful snippet.
    I asked about this in another post somehow i searchd 39 pages and got it!! hurray!!

    One thing, please add tag to the code. its missing
    I added for myself, I suggest this for others 🙂

  3. Thanks a lot!!!

  4. Thank you very much!!!

  5. Excellent Snippet! In one case, where i use the Custom Post Types UI Plugin, the name of the taxonomy is not shown up, whereas the number of taxonomy categories is shown. Any ideas?

    1.  Hnmm that is strange, I would make sure that you created your taxonomies and custom post types properly to see if that resolves the issue. I test snippets before posting and this does work properly, what version of wordpress are you current running?

      1. The site is on the wp 3.3.1 and i checked the taxonomy a few times. i guess its caused by the custom post types ui plugin, because on another site (with hand coded CPT in functions.php) the tax name is shown up. Thanks for your fast reply 🙂

  6. Is it possible to hide regular posts and show only the custom post types we want?

    1. If that is the case you may be better off to disable the right now widget and create a custom one with just what you need.

  7. Fantastic! This did EXACTLY what I needed. Brief and simple code without the need to install a plugin. It’s not often that you google for something and find precisely the right thing right away… Thanks a lot!

    1. Cool Leo, good to see this snippet was helpful. I have lots more snippets I hope that you can find something else that will help you out. 

  8.  Brilliant. Cheers for this.

    1. No problem enjoy

  9. Excellent 🙂 very usefull if having custom types

  10. ¡Excelente artículo!

    1. Thanks Heinrich glad you like it.

Añadir un comentario

Nos alegra que haya decidido dejar un comentario. Tenga en cuenta que todos los comentarios se moderan de acuerdo con nuestra política de privacidad , y que todos los enlaces son nofollow. NO utilice palabras clave en el campo del nombre. Tengamos una conversación personal y significativa.

WordPress Launch Checklist

La lista definitiva para lanzar WordPress

Hemos recopilado todos los elementos esenciales de la lista de comprobación para el lanzamiento de su próximo sitio web de WordPress en un práctico ebook.
Sí, envíeme el ¡gratuito!