X

Mostrar lista de autores en un menú desplegable usando wp_dropdown_users

Snippets by IsItWP

¿Buscas una forma de mostrar los autores de un blog en un menú desplegable? La lista de autores ayudará a los usuarios a encontrar entradas específicas del autor. Hemos creado un fragmento de código rápido que puede utilizar para mostrar la lista de autores en un menú desplegable utilizando wp_dropdown_users en WordPress.

Instrucciones:

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

<li id="users">
 <h2><?php _e('users:'); ?></h2>
   <form action="<?php bloginfo('url'); ?>" method="get">
   <?php 
     $args = array(
   	 'exclude'                 => '1',
   	 'name'                    => 'authors',
   	 'who'                     => 'authors'
    );
    wp_dropdown_users($args); 
   ?>
   <input type="submit" name="submit" value="view" />
   </form>
</li>

Nota: Si es la primera vez que añade fragmentos de código en WordPress, consulte nuestra guía sobre cómo copiar / pegar correctamente fragmentos de código en WordPress, para no romper accidentalmente su sitio.

Si le ha gustado este fragmento de código, por favor considere revisar nuestros otros artículos en el sitio como: Cómo crear un formulario de donación en WordPress y Cómo añadir un portafolio a su sitio WordPress.

Comentarios   Deja una respuesta

  1. it should actually be 'name' => 'author', (without the “s”) otherwise you will not end up on the authors profile page

  2. I have a Query. I need a dropdown list which should display users except the admin and the current user id who is logged in. How to accomplish this scenario?

  3. Hi there– this is great, two questions: 1. Where do I add this in my theme template? 2. How do I have it include only users with the role of “contributor”? Thanks!

  4. Kevin — maybe you can help. I’ve been searching for a couple days. I am after code to make a drop down list of POSTS. The Codex covers everything but that, which seems a strange oversight.

    I’ve found two sources, mainly the Dagon code which works but is too complex for my weak PHP skills to style (width and background color for example).

    I know that some javascript is needed to make the code dynamic, but it can’t be that complex. So, what is the magic bullet to turn a list of … anything into a drop down format? The Codex addresses pages, archives, tags, and about anything for drop downs except posts.

    Any guidance is appreciated
    Mike

    1. Hi Mike,
      Well this should solve your problem, http://pastebin.com/uAiujNYL
      If I could specify post_type within wp_dropdown_pages that would solve things but does not appear to work. However the code I put online at pastebin should work fine for you and nice and sample. Place that code in any location within your wordpress theme.

      1. Kevin, thank you!!! Works like a charm. NOW :), and I don’t mean to try your patience and time, but can you also tell how to add a line of javascript to make each drop down link clickable. I do have code from a site that has a permalink with a click but the problem is that there’s no –Select an item– as the first entry, the null value, so that this first item can never be used.  Need like (in the your drop down box):
        — Select an item —
        clickable item A
        clickable item B
        etc.

        Javascript is something I don’t enjoy LOL It is in no way intuitive. Anyway, this last piece will complete the puzzle. Again, I’ve played with the Dagon script but it’s too complex to alter.

        Mike

        1. Hi Mike ill post this as a snippet this week.

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!