WordPress.org

Ready to get started?Download WordPress

Forums

Display authors by category (15 posts)

  1. jgrieveson
    Member
    Posted 2 years ago #

    I have been developing a blog site for the past 2 weeks now, and have ironed out almost all of the kinks. One of the things the client has asked which I am currently unable to accomplish is having a 'Category' page that displays the authors that have posted stories in that specific category.

    The desired display would be something like this:

    CATEGORY 1:
    - JOHN
    - SUSAN
    - JUSTIN

    CATEGORY 2:
    - JOHN
    - RICK

    So, with this given information, John has posted in categories 1 and 2, Susan has only posted in category 1, and Rick has only posted in category 2.

    I have been messing around this this chunk of code, which displays all categories associated with a certain author, I guess I just need to reverse the information given/needed, but I can't think of how to implement it.

    http://pastebin.com/BTgbgSNz

    Any help would be greatly appreciated, as I am fast approaching my deadline!

    EDIT: the code snippet was found here: http://wordpress.org/support/topic/how-do-ilist-categories-an-author-has-wrote-in-on-authorphp

  2. bythegram
    Member
    Posted 2 years ago #

    I'm no pro but could you do two seperate queries then use wp_list_authors?

    $query = new WP_Query( 'category_name=category1' );
     <?php wp_list_authors( $args ); ?>
    $query = new WP_Query( 'category_name=category2' );
     <?php wp_list_authors( $args ); ?>

    Check out this link for more on "list authors"

    ps. my "code" mock up is probably not accurate at all but just the concept.

  3. jgrieveson
    Member
    Posted 2 years ago #

    @bythegram

    Thanks! I will be trying this now, logistically it seems correct

    EDIT: also, looking for a dynamic way to grab the categories, in case we add new ones in the future

  4. bythegram
    Member
    Posted 2 years ago #

    http://codex.wordpress.org/Function_Reference/get_the_category

    I think this might help.

    I'm attempting to do this myself to see if I can help more and am stuck on displaying the category names.

    I'll post again if I have any success.
    Best of luck!

  5. jgrieveson
    Member
    Posted 2 years ago #

    @bythegram

    After doing some looking in that link you gave me, I found that the category ID is being stored in the DB as term_id.

    I was kind of thinking of needing to do a custom query, but I'm still unsure.

  6. bythegram
    Member
    Posted 2 years ago #

    I think am so close.

    <?php $categories = get_categories(); foreach ($categories as $cat) :?>
    <?php wp_list_authors();?>
    <?php endforeach;?>

    This displays the Authors of each category separately. But I'm just stuck on displaying the category name.

  7. jgrieveson
    Member
    Posted 2 years ago #

    oh really? I'm on it too, touch base soon!

    Thanks!

    EDIT: get_post() has the ability to retrieve the user's ID and the category ID associated. How could be use this information to get what is required?

    I think get_post() is something we need to be using for this, not 100% though

  8. bythegram
    Member
    Posted 2 years ago #

    Got it!

    <?php $wp_query = new WP_Query( array('post_type' => 'post','posts_per_page'=> 10,));?>
    
    <?php while(have_posts()) : the_post(); ?>
    
    <?php foreach((get_the_category()) as $category) :?>
    <!--Style these how you would like-->
     <?php   echo $category->cat_name . ' ';?>
     <?php wp_list_authors(  ); ?>
    <!--/-->
    <?php endforeach ?>
    <?php endwhile;?>
  9. bythegram
    Member
    Posted 2 years ago #

    You can change the query however you wish so that it grabs the categories from the desired area (posts, pages, custom post types etc)

    Also if you look back into the first link about "list_authors" there is a ton of info on how you can style the list.

  10. jgrieveson
    Member
    Posted 2 years ago #

    That is super close! This is what I am getting when I implement this:

    testing category
    justin
    test
    Uncategorized
    justin
    test
    Uncategorized
    justin
    test
    tech2
    justin
    test
    Uncategorized
    justin
    test
    Tech
    justin
    test
    Uncategorized
    justin
    test
    testing category
    justin
    test
    Tech
    justin
    test
    Tech
    justin
    test
    Uncategorized
    justin
    test

    I only have: 'Uncategorized', 'tech', 'tech2', and 'testing category' as categories, and the user 'test' has only posted in one category, but is showing in all

  11. bythegram
    Member
    Posted 2 years ago #

    I'm stuck sorry. I think this is on the right track but will have to leave it for the weekend. The area I think is causing this is the query but I cant' seem to figure it out.

    Sorry, best of luck until someone more experienced comes along!

  12. jgrieveson
    Member
    Posted 2 years ago #

    Thanks a lot for the input, you have moved me in the right direction I'm sure.

    Anybody else out there with answers?

  13. bythegram
    Member
    Posted 2 years ago #

    So I've had another look at this and I've got closer;

    check it out

    The issue I have now is that it shows the author of each post (which will result in duplicates most likely).

    I'll still work away at this on my down time until someone with a better solution pops up. (or just tell me to bugger off if I'm not on the right track lol)

  14. bythegram
    Member
    Posted 2 years ago #

    oh and just change the line that says 'List of Posts in' to 'Authors in' or you can leave blank if you'd rather just show the category name

  15. jgrieveson
    Member
    Posted 2 years ago #

    You are absolutely on the right track with this! I will show my coworker tomorrow, I think now the only issue is having a DISTINCT selector somewhere in the SQL call, I don't know right now, will look at this tomorrow!

    Thanks!!

Topic Closed

This topic has been closed to new replies.

About this Topic