WordPress.org

Ready to get started?Download WordPress

Forums

wp list authors by role (11 posts)

  1. Ronny
    Member
    Posted 8 years ago #

    hey guys.
    regarding this tag

    <?php wp_list_authors('arguments'); ?>
    located here
    http://codex.wordpress.org/Template_Tags/wp_list_authors

    are there any arguments that allow you to list authors in a particular role

    i.e
    <?php wp_list_authors('contributors'); ?>
    to onyl show authors/users with the role of contributor?

    thanks guys.
    Ronny.

  2. Kafkaesqui

    Posted 8 years ago #

    No. The only author-type argument for list_authors() / wp_list_authors() is the parameter to exclude the admin account.

  3. portalpie
    Member
    Posted 7 years ago #

    Hello,

    Is this at least possible? I would like to be able to list Authors on my site this way too. Is it hard to implement?

    Thanks

  4. Kafkaesqui

    Posted 7 years ago #

    "Is this at least possible?"

    Of course it's possible.

    But you're asking for a replacement of {wp_}list_authors() to output users within a certain role. Here's a plugin which provides that:

    List Authors By Role plugin
    Download plugin | View source

    Download the plugin file, upload it to your plugins directory, then activate List Authors By Role under Plugins. You can make use of one of two functions (i.e. template tags):

    <?php list_authors_by_role(); ?>
    <?php szub_list_authors_by_role(); ?>

    Both accept the same parameters as their internal WordPress counterparts, but offer an additional one to restrict by role.

    The new parameter in list_authors_by_role() is appended to those for list_authors(). Using szub_list_authors_by_role(), pass the 'role' parameter like so:

    <?php szub_list_authors_by_role('role=contributor'); ?>

    Separate multiple roles with a comma:

    <?php szub_list_authors_by_role('role=author,contributor'); ?>

  5. portalpie
    Member
    Posted 7 years ago #

    Ask and ye shall receive.

    Thanks Heaps!

  6. portalpie
    Member
    Posted 7 years ago #

    OK, well that did not go as smoothly as I would have liked.

    I am guessing that this plugin does not work with Role Manager???

    Otherwise I am simply doing something wrong in Sidebar Modules.

    Thanks

  7. portalpie
    Member
    Posted 7 years ago #

    OK, so my php module is working and there is no plugin conflict with role manager, but i still have a problem:

    If I use this code:
    <?php szub_list_authors_by_role(); ?>
    I get nothing. But if I use this code:
    <?php list_authors_by_role(); ?>

    I get a list but I get everyone from all roles. I would like to generate 2 lists, one with a list of Authors and one with a list of Contributors. I think that I may be just miss understanding the explanation above. Could you hold my hand a little longer please?

    Thanks
    Morgs

  8. Kafkaesqui

    Posted 7 years ago #

    Realized there was a little 'oops' in the code that may have caused a problem for you here. I forgot the capabilities (i.e. role) record in the usermeta table made use of the table prefix for the meta_key, so I had hardcoded wp_ as part of the query. This is fixed in the version of the plugin now online (R1.0.1).

    Anyway,

    1. It will work with Role Manager.

    2. Both functions you list above when providing no arguments should list all authors (or whatever) with one or more posts. In other words, it works the same as {wp_}list_authors().

    3. To generate your two lists:

    <?php szub_list_authors_by_role('role=author'); ?>

    <?php szub_list_authors_by_role('role=contributor'); ?>

  9. portalpie
    Member
    Posted 7 years ago #

    Hello Kafkaesqui,

    I finally got it to work. It was my fault. I was using role names with spaces and capitals.

    I think there might be just on little bug in your code. There are no <ul> & </ul> tags. I did try putting them n the loop myself, but not enough skill to make the /ul appear only once.

    Thanks heaps for your help.
    Morgs

  10. Kafkaesqui

    Posted 7 years ago #

    If there's a bug, then I merely copied it over from list_authors(). :)

    However, I wouldn't call this a bug at all. list_authors() (and so by extension, szub_list_authors_by_role()) is one of the few list-displaying template tags that assume it's being nested in the appropriate HTML element. So you can do:

    <ul>
    <?php szub_list_authors_by_role(); ?>
    </ul>

  11. portalpie
    Member
    Posted 7 years ago #

    Sorry if Bug offended. I am but a mere amateur trying to use the lingo. I completely understand what you mean. I have just learnt something that I will be able to apply again and again.

    Thanks again. Everything works now just how I was hoping it would.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.