表达式引擎 SQL 查询帮助 - 作者的最新帖子
可能的重复:
表达式引擎sql查询条目按作者列出
我正在尝试创建频道中最新帖子的简短侧边栏列表,每个帖子均由单独的作者撰写。 有人可以帮忙合并我认为我(有点)单独工作的这些查询吗?
格式:
screen name
thumbnail
title
此查询代码创建一个列表,但使用author_id而不是屏幕名称 标题工作正常,但缩略图无法加载,路径也无法正确写入。
{exp:query sql="SELECT t.title, t.author_id FROM exp_channel_titles t
ORDER BY author_id ASC LIMIT 4"}
{author_id}<br />
<a href="{path=portfolios/gallery/{username}}"><img src="{thumbnail}"></a><br>
<a href="{path=portfolios/gallery/{username}}">{title}</a><br />
{/exp:query}
此查询代码正确创建路径和用户名,但标题仅显示为 {title} 缩略图未加载。
{exp:query sql="SELECT m.member_id, m.username, m.screen_name, m.avatar_filename FROM exp_members m
WHERE m.group_id='5' "}
{screen_name}
<a href="{path=portfolios/gallery/{username}}"><img src="{thumbnail}"></a><br>
<a href="{path=portfolios/gallery/{username}}">{title}</a><br />
{/exp:query}
我想我需要使用 JOIN 但我真的不是 SQL 查询方面的专家。
缩略图是 exp_channel_fields 中的一个字段 - 知道如何将其放入查询中吗? 图像的文件名位于 exp_channel_data 中,但它是这样的 -
{filedir_1}13.jpg
如何删除该
{filedir_1}
位或创建路径?
或者我应该在那里使用 {exp:channel: ?
Possible Duplicate:
expression engine sql query entries list by authors
I’m trying to create a short sidebar list of latest posts from a channel, with each post by a separate author.
Could someone help as regards merging these queries I think I have (sort of) working separately?
format:
screen name
thumbnail
title
this query code creates a list, but with author_id rather than screen name
title works ok, but the thumbnail doesn’t load and the path doesn’t write properly.
{exp:query sql="SELECT t.title, t.author_id FROM exp_channel_titles t
ORDER BY author_id ASC LIMIT 4"}
{author_id}<br />
<a href="{path=portfolios/gallery/{username}}"><img src="{thumbnail}"></a><br>
<a href="{path=portfolios/gallery/{username}}">{title}</a><br />
{/exp:query}
This query code create the path properly and the user name properly but the title is just appearing as {title}
thumbnail doesn’t load.
{exp:query sql="SELECT m.member_id, m.username, m.screen_name, m.avatar_filename FROM exp_members m
WHERE m.group_id='5' "}
{screen_name}
<a href="{path=portfolios/gallery/{username}}"><img src="{thumbnail}"></a><br>
<a href="{path=portfolios/gallery/{username}}">{title}</a><br />
{/exp:query}
I presume I need to use a JOIN but I’m really not that expert with SQL queries.
thumbnail is a field in exp_channel_fields - any idea how I get this into the query?
the filename for the image is in exp_channel_data but it is like this -
{filedir_1}13.jpg
how do I get rid of the
{filedir_1}
bit or create a path?
or should I be using {exp:channel: in there as well ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里最好的方法是,因为您需要解析自定义字段,所以首先找到来自不同作者的最新 4 个条目的entry_ids,然后使用
entry_id
参数。这应该可行(请务必将
channel_id
替换为适当的整数):然后您的 embeds/_latest_per_member 模板可能如下所示:
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):Then your embeds/_latest_per_member template can look something like this: