ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ordered list of authors from multi-author posts. Hmmmm.

May 17, 2008 11:33pm

Subscribe [1]
  • #1 / May 17, 2008 11:33pm

    sahadeva

    14 posts

    First problem
    Most of the posts from my EE blog have multiple authors. I’d like to create a list of authors, ordered by their last names, where the author names link back to the post they’ve authored. I have a set of custom fields for the authors’ first names and another set for their last names (i.e. author_A_firstname, author_A_lastname, author_B_firstname, author_B_lastname). Here’s my go at it (I put the conditionals in there to make sure that posts with just one type of author were pulled in, but I’m not really sure I need them).

    <div>
            <ul>
    {exp:weblog:entries weblog="{my_weblog}"  orderby="author_A_lastname&author;_B_lastname" sort="asc"}
           {if author_A_firstname}
                   <li><a href="http://{url_title_path=">{author_A_firstname} {author_A_lastname}</a></li>
           {/if}
           {if author_B_firstname}
                   <li><a href="http://{url_title_path=">{author_B_firstname} {author_B_lastname}</a></li>
           {/if}
    {/exp:weblog:entries}
            </ul>
    </div>

    Out of that I get a list of authors linked correctly, but the list ordered by the date those posts were published, not alphabetically by the “author’s last name” custom fields… I’m aware of this thread, and a few others, but it hasn’t been any help. Thoughts?

    Second problem
    The step after this would actually be to create a set of links in case the author had multiple posts; if the author has only one post attributed to him link the name directly to that post, otherwise don’t link the name a create a list of numbers linked to those posts, i.e.

    Jack Bender
    Sarah Conner
    Curtis Dover (1, 2)
    John Franklin
    Anna Sakura (1, 2, 3)

    I think I want to do something like:

    IF author_A_firstname AND author_A_lastname exist together ONCE create a link out of the name; ELSE IF author_A_firstname AND author_A_lastname exist together more than once write name and create a list of posts with the custom field author_A_firstname & author_A_lastname.

    Any ideas on how to get started on that?

  • #2 / May 18, 2008 10:37am

    Robin Sowell

    13255 posts

    OK- for the first on, try it with a pipe rather than an ampersand:

    orderby="author_A_lastname|author_B_lastname"

    This should sort properly, but I’m not sure it’s going to sort how you want it.  Basically- sort works like- sorts by the first requirment- everything sorted by author_A_lastname.  When you have two or more identical author_a’s?  Within those, it will sort by author_b_lastname.  Like I say- I’m not dead sure that’s what you want.  But it’s how it should work.

    That get any closer?

    For the second issue?  A stock way to do this isn’t coming to mind.  If I understand what you’re going for- the weblog tag simply doesn’t have the data at this point to do what you want- which is create a series of links to every other post containing that name combo.  In truth- I’d consider setting this up using related entries- each author being an entry in an ‘author’ weblog, or tags.  Or- I’d start digging into a custom query.

    If this was a single entry page- where you have only one entry returned by the weblog tag?  You could likely nest a weblog tag- use the search parameter to pull back just the entries w/that name combo.  Should be doable- but too resource intensive for a multi-entry page- as the nested tag would be run for every entry returned in the initial weblog tag.

    Anyhoo- I suspect this needs to be shifted to ‘How to’ for brainstorming.  But I want to confirm- it is sorting as it should be- correct?  Given my explanation of the way sort would be expected to work.

  • #3 / May 18, 2008 11:58am

    sahadeva

    14 posts

    The pipe doesn’t seem to be helping with the list ordering. Here’s what I’m getting right now, vs. how I’d like it to be ordered (all I changed in the code is the addition of the pipe):

    Now (by date posted):

    John Sorp [author A post 1]
    David Apple [author B post 1]
    Sarah Connor [author A post 2]
    Emily Konnard [author B post 2]
    Erin Song [author A post 3]
    July Child [author B post 3]

    Would like (alphabetically by last name):

    David Apple [author B post 1]
    July Child [author B post 3]
    Sarah Connor [author A post 2]
    Emily Konnard [author B post 2]
    Erin Song [author A post 3]
    John Sorp [author A post 1]

    As for the second question, sure, if “how-to” is more appropriate shift the question over. Can you explain a bit more about what you mean by using related entries or give me some links to the appropriate documentation? Many thanks.

  • #4 / May 18, 2008 12:23pm

    Robin Sowell

    13255 posts

    See- the problem is- you’re sorting entries.  You can’t split up the bits from a given entry- which is what you want to do- see how your desired format has author b from post 1 separated from author a post 1?  It’s not going to work like that.  Your actual results don’t make sense to me- but I don’t know there’s much point in tweaking them, because it’s not going to work like you want regardless.

    Let me shift this over to ‘How to’- I suspect I might start with a custom query.  The end goal is a list of all authors- represented by 4 custom fields- for first and last names of author a and author b.  Correct?  And you want…  The b authors listed first, ordered by last name, followed by the a authors, sorted by last name?  And include basically a list of all entries for each author?

    And- shifting to ‘How to’ now.

  • #5 / May 18, 2008 7:49pm

    sahadeva

    14 posts

    I see what you mean when you say I’m sorting entries. Is there a reason I couldn’t essentially link to a post twice, though? That is, is there a way to list all entries with an author_A_firstname field and another list with entries containing an author_B_firstname field and mix them together and order by last names (I’d rather it was one list, not two as you suggest)? Is it possible to next to weblog expressions inside a larger one so something like that could be done?

    And yes, then list entries from that combination of first/last name if there are more than one (e.g. ‘Sarah Jones - 1, 2, 3’ where the numerals are links to those posts).

    Not sure why the actual results I’m getting confuse you—it’s essentially a list of three posts, each one with two authors, where those posts are ordered by date posted… Does that help? Any clues about how you’d go about turning this into a custom query?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases