I have a related question: how can I display the most recent weblog entry by random author? So rather than bio I’d like to querry for title, summery etc. for a specific weblog, in addition to author screen name and photo.
Here’s how I’m showing author photo
{exp:weblog:entries weblog="example" limit="1" orderby="date"}
<img src="http://example.com/ee/images/member_photos/{exp:pd_memberinfo field="photo_filename"}{author_id}{/exp:pd_memberinfo}" width="{exp:pd_memberinfo field="photo_width"}{author_id}{/exp:pd_memberinfo}" height="{exp:pd_memberinfo field="photo_height"}{author_id}{/exp:pd_memberinfo}" alt="" />
{/exp:weblog:entries}
Pretty clunky, but the best I could figure. Is there a better way?
I was looking for a way to display entries by random authors and found this thread. I didn’t know that EE allows us to nest exp:weblog tags inside exp:query tags but I gave it a try anyway. Now it looks like it’s doing what I need.
First I use SQL to query for random usernames from the exp_members table checking if they have entries using the last_entry_date column, then I just use the username tag inside the exp:weblog tag.
{exp:query sql="SELECT username FROM exp_members WHERE group_id='17' AND last_entry_date > 0 ORDER BY rand() LIMIT 3"}
{exp:weblog:entries weblog="sl_main" status="not closed" dynamic="off" disable="pagination|trackbacks" username="{username}" limit="1"}
{if avatar}
{avatar_url}
{if:else}
/images/spacer.gif
{/if}
{title}
{exp:word_limit total="15"}
{body}
{/exp:word_limit}
{/exp:weblog:entries}
{/exp:query}
I’m surprised that EE can handle this. Even if it isn’t an elegant solution, EE seems to figure it out.
This is a great tip. Thanks everyone.
One question (as I am a n00b with queries)…
How can you make the query return ONLY members whose data are NOT empty? Specifically, I only want to display members who have data in both “bio” and “avatar_filename”. I’ve tried the !=”” route, but no luck.
Thanks!
EDIT
I figured it out. I was using double quotes (!=”“) instead of single quotes (!=”). Duh!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.