Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Content Management System (http://www.go4expert.com/articles/cms/)
-   -   Getting Wordpress Blog Authors in Combobox (http://www.go4expert.com/articles/getting-wordpress-blog-authors-combobox-t21327/)

shabbir 12Mar2010 20:01

Getting Wordpress Blog Authors in Combobox
 

Introduction



I expected wordpress to have some built in support for listing all authors of the blog in a select box but that is not the case yet in Wordpress 2.9.2.

I was certain that I can get this done using wp_list_authors but actually it was a not that straight forward and so let me share this with you. I think this will help those looking for such functionality.

The Code



What I did is replaced the content of list items ( <li> ) into select box options ( <option> ) and added a JavaScript function to redirect user to the url when there is a change in the selection in the selection box.

So here is the code.
Code:

<select id="AuthorList" name="AuthorList" onchange="goAuthorList();">
        <?php
        $authargs = array(
                'optioncount'  => false,
                'exclude_admin' => false,
                'show_fullname' => false,
                'hide_empty'    => true,
                'echo'          => false, // We will not output using the function.
                'feed'          => false,
                'feed_image'    => false,
                'style'        => 'list',
                'html'          => true
        );
        $var_list = wp_list_authors( $authargs ); // Take the output into a variable.
        // Replace the tags of list to option box
        $var_list = str_replace("</a></li>","</option>",$var_list);
        $var_list = str_replace("<li><a href=","<option value=",$var_list);
        // Now output the list
        echo $var_list;       
        ?>
</select>
<script language="JavaScript">
<!--
    function goAuthorList() {
        // JavaScript function to change the user to the url of the author
                theSelAuthor = document.getElementById("AuthorList").value;
                        if ("" != theSelAuthor) location.href = theSelAuthor;
    }
//-->
</script>

Enjoy !!!

hanleyhansen 12Mar2010 23:01

Re: Getting Wordpress Blog Authors in Combobox
 
Cool!

pankaj.sea 14Mar2010 07:54

Re: Getting Wordpress Blog Authors in Combobox
 
Nice Info!
:)

shabbir 2Apr2010 09:11

Re: Getting Wordpress Blog Authors in Combobox
 
If you like this this article nominate it for Article of the month - Mar 2010

shabbir 16Apr2010 19:44

Re: Getting Wordpress Blog Authors in Combobox
 
Vote for this article for Article of the month - Mar 2010

johnny.dacu 30Jul2010 20:19

Re: Getting Wordpress Blog Authors in Combobox
 
Why to list authors in a select? What's wrong with a list style?

rohan123 5Apr2011 18:06

Re: Getting Wordpress Blog Authors in Combobox
 
Very Informative.
Thanks.

contusvideo 26Apr2011 14:51

Getting Wordpress Blog Authors in Combobox
 
:seeya:Really nice info, Good contributory share :detective @ shabbir! :2thumbsup


All times are GMT +5.5. The time now is 08:40.