Está procurando uma maneira de exibir os autores do blog em um menu suspenso? A listagem de autores ajudará os usuários a encontrar publicações específicas do autor. Criamos um trecho de código rápido que você pode usar para exibir uma lista de autores em um menu suspenso usando wp_dropdown_users
no WordPress.
Instruções:
Tudo o que você precisa fazer é adicionar esse código a um arquivo de tema ou em um plug-in específico do site:
<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>
Observação: Se esta é a primeira vez que você adiciona trechos de código no WordPress, consulte nosso guia sobre como copiar/colar corretamente trechos de código no WordPress para não danificar seu site acidentalmente.
Se você gostou desse snippet de código, considere dar uma olhada em nossos outros artigos no site, como: Como criar um formulário de doação no WordPress e Como adicionar um portfólio ao seu site WordPress.
it should actually be
'name' => 'author',
(without the “s”) otherwise you will not end up on the authors profile pageI 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?
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!
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
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.
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
Hi Mike ill post this as a snippet this week.