• I’ve search and even tried the coffee2code plugin, but it’s not providing the flexibility desired.

    I want to be able to have 10+ authors, but on the index page only display the most recent post by each of the authors. With links to more posts of course. Any suggestions?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You need to do a quick SQL query to retrieve all authors, then run query_posts to generate a separate post loop on each one. This would replace The Loop presently in your index.php:

    <?php
    global $wpdb;
    $authors = $wpdb->get_col("SELECT ID FROM $wpdb->users WHERE user_level > 0");
    foreach($authors as $author) :
    query_posts("author=$author&showposts=1");
    if(have_posts()) the_post();
    ?>

    <h3>Latest post from <?php the_author(); ?></h3>

    Place regular “Loop” tags and elements here.

    Read all posts by <?php the_author_posts_link(); ?>

    <?php
    endif;
    endforeach;
    ?>

    Note for WordPress 2.0 (and so on):

    Performing the query as above on $authors in 2.0 will be a bit more complicated. We need to query a different table (wp_usermeta), but mainly the issue is what represents an “author”. Users receive ‘roles’ in 2.0, and these run by default from subscriber (equivalent to level 0 (Registered User) in 1.5 and below) to contributor, author, editor and finally administrator.

    It’s possible all roles above subscriber on your blog will be considered “authors”. Or perhaps only contributor and author, or some other combination of the various roles. But in any case it’s something that needs to be accounted for (correctly) in the query. In the replacement example below, all roles (above subscriber) are matched in the meta_value column’s array by using the REGEXP comparison operator:

    $authors = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value REGEXP \"contributor|author|editor|administrator\"");

    (Slashes in code above intended)

    To remove one or more roles from the query, make sure to remove the accompanying separator (bar: | ).

    Thread Starter cpoteet

    (@cpoteet)

    I’m getting parse errors. I tried to replace the entire loop with the code, but I’m getting nothing.

    http://www.yahwehonline.com/

    I hope I am not bumping a topic that should have vanished a long time ago. I tried searching but couldn’t quite come up with a related post. So here is my problem:

    I want to get all the authors of a blog listed on one page. Therefore I have used the get_author_profile plugin. Since the blog will have many contributors/authors there is no way I am going to set up a profile for everyone (too much work and maintenance). Thus I have looked into running the plugin in a loop but have failed. Mostly because I don’t code or don’t know how.

    From what I have gathered the query for users has changed in the database from 1.5 to 2.0. I tried c&p the above mentioned. This has resolved on error code and puts out a new one instead.

    Warning: Invalid argument supplied for foreach() in ...

    I guess that means that the loop in itself is somewhere incorrect.

    Would a kind soul help me please? I’d be very happy.

    The site in question would be http://www.idleware.com/trickfilmklasse/about/

    The php in question is stored here (link)

    I want to get all the authors of a blog listed on one page.

    http://wordpress.org/support/topic/94546#post-478885

    Kafkaesqui, I am deeply appreciative. Thanks.

    😀

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Posts by Author’ is closed to new replies.