WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get_author_profile plugin in a loop? (10 posts)

  1. Kathy_P
    Member
    Posted 8 years ago #

    I am interested in making a Contributors page that lists all users who have written entries (either posts or pages), giving basic information such as their email, website, and profile but not their posts. (But it would be nice to have the author's name link to the corresponding author.php page.) I can see that the Get Author Profile plugin would be perfect for this, but is there some way to get it to run in a loop instead of having to write the same code over again for each author? Something along the lines of:
    <div class="profile">
    For each author, do these steps
    <ul>
    <li id="myprofile">Blog Owner:
    <ul>
    <li><?php author_profile('firstname'); ?> <?php author_profile('lastname'); ?></li>
    <li>ICQ: <?php author_profile('icq'); ?></li>
    <li>AIM: <?php author_profile('aim'); ?></li>
    <li>Notes: <?php author_profile('profile'); ?></li>
    </ul>
    </li>
    </ul>
    until there are no more authors left
    </div>

    (The code is taken directly from the plugin author's site:
    http://guff.szub.net/2005/01/31/get-author-profile/) If it was in a loop that executed the code for each author found, then the code would not have to be changed every time a new author was added. If I've got the general idea right, could someone come up with the actual code?

  2. Kafkaesqui

    Posted 8 years ago #

    First I'd recommend grabbing the update to Get Author Profile. Coming across this thread caused me to look at it--which I've not done in a while-- and I noticed and fixed a problem with it in 1.5. Added a small enhancement for author template use, as well.

    Anyway, here is a bit of code which should do what you're after:

    http://paste.uni.cc/7475

    Notes: Change $owner value at the top to *your* user ID. The SQL query ($user_ids) calls up all users above level 0 (i.e. authors). You could modify this to restrict to specific levels (or a range), remove the admin account (or other) account, etc.

  3. Kathy_P
    Member
    Posted 8 years ago #

    Thank you very much, Kafkaesqui. You've certainly helped a lot, and I've benefited from your help in other threads as well. I noticed you made a distinction between the owner of the blog and the rest of the authors. Is there a code reason for doing that, or was it just what you thought might be wanted? Since I imported from MT, I am already in the database as an author as well as the administrator, and I don't want to be listed twice. Is there any reason why I couldn't use the code you've provided as follows?

    I don't know php, but I'm guessing if($user_id != $owner) means" if the user_id string is not the owner string."So to leave out the admin account I would use lines 1-5, 7 to set the owner string and format with css, and then skip to line 17. (I might have missed some css markup, I can't "read" it that well.) In other words, you tell the program who the owner is, and then tell it to run the loop for everyone above user level 0 who isn't the owner. Do I have that right?

    I can see that line 18 controls the user level, but how do I check for users above level 0 who haven't written any entries? I suppose it might be easier to demote them.

  4. Kafkaesqui

    Posted 8 years ago #

    " I noticed you made a distinction between the owner of the blog and the rest of the authors."

    I did it only to reflect your code example above (I obviously misread your intent). But no, there's no reason to---but vanity. You could remove the first block and change:

    if($user_id != $owner) :

    to

    if($user_id != 1) :

    That will pass over the admin account.

  5. Kathy_P
    Member
    Posted 8 years ago #

    Thank you once again. The code example was taken directly from your page on the plugin, and I didn't modify it because I wasn't sure which parts were essential. I now have a better understanding of what's going on with that code.

  6. Kafkaesqui

    Posted 8 years ago #

    "The code example was taken directly from your page on the plugin"

    Gee, one would think I'd have known that... ;/

  7. Kathy_P
    Member
    Posted 8 years ago #

    I didn't mean to annoy by stating the obvious, but not everyone who reads this thread will find it obvious. I've run into one little problem using the code provided in the paste bin. I can't seem to change this
    <a href="mailto:<?php echo antispambot(get_the_author_email()); ?>">email
    author</a>

    (sample code obtained here) into something that the Get Author Profile can process. I tried using
    <a href="mailto:<?php echo antispambot(<?php author_profile('email'); ?>); ?>">email
    author</a>
    but I get this error:
    Parse error: parse error, unexpected '<', expecting ')' in /home/coldclim/public_html/wp-content/themes/connections/contributors.php on line 39
    What am I doing wrong?

  8. Kafkaesqui

    Posted 8 years ago #

    You can't nest php tags (<?php .. ?>); common mistake. Also, author_profile() echoes directly, so you can't use it in another function. Try this instead:

    <a href="mailto:<?php echo antispambot($author_email); ?>">email author</a>

  9. Kafkaesqui

    Posted 8 years ago #

    Hmm, that doesn't seem to take (anymore) without "scoping" $author_email as global. So instead go with:

    <a href="mailto:<?php global $author_email; echo antispambot($author_email); ?>">email author</a>

    I also updated the plugin (again!) with a 'display' or echo parameter to author_profile(). Now you can tell it to either echo the value, or return it (to do things like assign it to a variable or as a function argument). Really should have been there from the beginning.

  10. Kathy_P
    Member
    Posted 8 years ago #

    Thank you once again, Kafkaesqui.

Topic Closed

This topic has been closed to new replies.

About this Topic