表达式引擎 SQL 查询条目作者列表
我如何从一个频道订购最新的 3 个条目,每个条目都来自不同的作者? (所以它们最终不会成为同一作者的 3 个最新条目) - 我想我需要使用 SQL 查询吗?
{exp:channel:entries orderby="screen_name|date" channel="portfolios" limit="3" group_id="5" dynamic="no"}
<img src=" {thumbnail}" alt="{title}"/><br />
{title}<br />
{/exp:channel:entries}
提前致谢!
How would I order the latest 3 entries from a channel with each entry from a different author? (so they don't end up being 3 latest entries by the same author) - I think I need to use an SQL Query for it?
{exp:channel:entries orderby="screen_name|date" channel="portfolios" limit="3" group_id="5" dynamic="no"}
<img src=" {thumbnail}" alt="{title}"/><br />
{title}<br />
{/exp:channel:entries}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
马克 - 这是我在 其他骗局上发布的答案的转发问题:
这里最好的方法是,因为您需要解析自定义字段,所以首先找到来自不同作者的最新 4 个条目的entry_ids,然后将它们传递给
channel:entries
标记通过使用entry_id
参数嵌入。这应该可以工作(请务必将
channel_id
替换为适当的整数)。将当前的整个代码块替换为:然后您的 embeds/_latest_per_member 模板可能如下所示:
您曾提到此代码给您带来了递归错误 - 这意味着您已经进行了另一个调用到嵌入内的嵌入。不要那样做。
Mark - here's a repost of the answer I posted on the other dupe question:
The best approach here, since you need your custom fields parsed, is to first find the entry_ids of the latest 4 entries from distinct authors, and then pass those to the
channel:entries
tag through an embed using theentry_id
parameter.This should work (be sure to replace the
channel_id
with the appropriate integer). Replace your entire current chunk of code with this:Then your embeds/_latest_per_member template can look something like this:
You had mentioned that this code gave you a recursive error - that means that you've put another call to the embed within the embed. Don't do that.
WHERE IN (SELECT MAX(entry_date)...) 示例对数据库造成了巨大的影响。它似乎本质上为每个条目执行一个子查询。我发现的另一种选择(Stackoverflow)仅在 FROM 部分中使用一个子查询,
引用:Do a GROUP BY after通过用 GROUP BY 包装查询来实现 ORDER BY:-)。
无论如何......这会获取所有作者及其最后发布的条目标题。如果您还需要 url_title,则必须将其添加到两个 SELECT 语句中。我添加了一些额外的选项,仅获取最近 4 个月的数据,仅限于channel_id 8,并仅限于category_id 68。
The WHERE IN (SELECT MAX(entry_date)...) example took a huge hit at the database. It seems to essentially do a subquery for each entry. An alternative i found (Stackoverflow) uses just one subquery in the FROM part,
quote: Do a GROUP BY after the ORDER BY by wrapping your query with the GROUP BY :-).
Anyway ... This fetches all authors and their last posted entry title. If you also want the url_title, you have to add it to both SELECT statements. I've included some extra options, fetch only for the last 4 months, limited to channel_id 8, and limit to category_id 68.