3

On an article page, I'm trying to output "more from this author" using the User add-on from Solspace.

Unfortunately, there's a bug in the current version that prevents this from working:

{exp:user:entries channel="articles" status="open" user_author_id="1" entry_id="not 344"}
    {if count == "1"}
    // header and opening ul
    {/if}

        // list items with links to articles

    {if count == total_results}
    // closing ul
    {/if}
{/exp:user:entries}

The bug means that entry_id doesn't work with the "not" in there, so I can't exclude the current entry.

The workaround is to use PHP, and so I have something like this:

<?php $c = 0; ?>
{exp:user:entries channel="articles" status="open" user_author_id="1" limit="4"}
  {if entry_id != "344"}
    <?php $c++; ?>
    <?php if($c == 1): ?>
      <h3>More from this Author</h3>
      <ul class="author-more">
    <?php endif ?>

        <li><?php echo $c ?> <a href="/article/{url_title}">{title}</a></li>

  {/if}
{/exp:user:entries}
<?php if($c != 0) :?>
      </ul>
<?php endif ?> 

Unfortunately, the results I'm getting are odd. I'm getting a list of three articles — the article with the id of 344 is being correctly omitted — but I'm not getting the header and open ul tag.

I'm echoing $c in there, and what results is a list of three articles numbered 2, 3, 4. It seems like $c is skipping straight from 0 to 2.

Hopefully I'm just doing something dumb...

  • I'm unclear why adding {if entry_id != "344"} required you to switch to PHP inside the loop? The workaround for being unable to use not in the entry_id param is the if statement, yes? – Mark J. Reeves Feb 5 '13 at 17:13
  • I needed the PHP to keep an independent count. With just the ExpressionEngine logic, even though the statement {if entry_id != "344"} will eliminate the entry I don't want to include, it won't affect the main loop, and EE's count will still iterate as normal. One result being if the article I want to eliminate is the only article by this author, even though the if statement will prevent it from being displayed, the EE count is still "1", and I get a header and empty ul. – Tim Feb 5 '13 at 22:02
2

You might be able to stick to EE code with the following?

Maybe relying on total_results & count would do it, and then within you could check for the current entry_id to skip that one.

{if total_results>1}
{if count==1}
<!-- Set up header & UL -->
{/if}
{if entry_id != 344}
<!-- Output entry details -->
{/if}
{if:elseif count==1 && total_results==1}
{!-- This would never happen, right? Because if total_results==1, then you're looking at the only entry. So all you need is the single if --}
{/if}

Just to clarify what I've written there: I included an else statement for when there's only 1 result. But you'd never want that. Because the 1 result would be 344, and you don't want to show anything if that's the case.

If you kill the elseif, you can just do 2 separate if statements, right?

{if count==1 && total_results>1}
<!-- Set up header & UL -->
{/if}
{if entry_id != 344}
<!-- Output entry details -->
{/if}

Is that what you're looking for? Or am I missing something?

| improve this answer | |
  • You have a really good point in that if the total count is 1, it's the entry you're on. – Tim Feb 5 '13 at 22:51
  • That was it. Just needed more logic, not more code. – Tim Feb 5 '13 at 23:27
3

Oof, that's a lot of ugly PHP to have to add to get around a bug. May I suggest a couple of alternatives?

One would be to just fix the bug while you wait for Solspace to release an update. (Ha.)

But failing that, use the Query module to grab all of an author's entries and pass them to a standard channel entries loop (which you can then use your standard limit, orderby, etc on).

{embed="_embeds/_more_by_author" entry_ids="{exp:query sql="SELECT DISTINCT entry_id as user_entry_id FROM exp_user_authors WHERE author_id = {author_id} and entry_id != {entry_id}" backspace="1"}{user_entry_id}|{/exp:query}"}

(Since we're using variables from your currently-displayed entry, this would have to be inside your primary Channel Entries loop.)

Then in your embed:

{exp:channel:entries channel="articles" status="open" entry_id="{embed:entry_ids}"}
    {if count == "1"}
    // header and opening ul
    {/if}

        // list items with links to articles

    {if count == total_results}
    // closing ul
    {/if}
{/exp:channel:entries}
| improve this answer | |
  • thanks for the reply. the sql statement is blowing up, unfortunately. if i remove ` and entry_id != {entry_id}` it seems to work. – Tim Feb 4 '13 at 17:40
  • if i hard code values, it does not blow up. – Tim Feb 4 '13 at 17:42
  • ahh, I think i know why it's blowing up, it's my bad — belay those comments. – Tim Feb 4 '13 at 17:55
  • Currently belaying. – Derek Hogue Feb 4 '13 at 18:08
  • ok, i'm close, but {member_id} isn't parsing. here's my php error: SELECT DISTINCT entry_id as user_entry_id FROM exp_user_authors WHERE author_id = {member_id} and entry_id != 15326 (this is when I run the query inside the embed statement) – Tim Feb 4 '13 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.