Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2020-09-22 08:43:31
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 162
Show list of users who have already posted to a section
I have a section called “Blog”, and I would like to show a list of users, but only those who have already published an article in the Blog section. It’s possible?
Offline
Re: Show list of users who have already posted to a section
You can, in core, but it would be not optimal. Like output a list of ‘Blog’ articles ordered by author and use <txp:if_different />
to display each author only once?
Offline
#3 2020-09-22 09:57:26
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 162
Re: Show list of users who have already posted to a section
etc wrote #325998:
You can, in core, but it would be not optimal. Like output a list of ‘Blog’ articles ordered by author and use
<txp:if_different />
to display each author only once?
I never need to use <txp:if_different/>
before. I don’t understand how it works yet. Do you say something like that?
<ul>
<txp:article_custom section='blog' sort="AuthorID">
<txp:if_different>
<li><txp:author/></li>
</txp:if_different>
</txp:article_custom>
</ul>
Do you have a quick explanation of why it is not optimal?
Last edited by Myusername (2020-09-22 10:04:03)
Offline
Re: Show list of users who have already posted to a section
Myusername wrote #326003:
I never need to use
<txp:if_different/>
before. I don’t understand how it works yet. Do you say something like that?
Yes, exactly. <txp:if_different />
outputs its content when it differs from the previous call.
Do you have a quick explanation of why it is not optimal?
This code will loop through all articles. If you have many articles and only few authors, most of these loops will be useless. I guess a direct db query with DISTINCT
clause would be faster, but we do not allow direct queries in core (plugins can do it).
You can go another way: generate an authors list via <txp:authors />
and check inside it for each author whether he has ‘Blog’ articles via <txp:article_custom author='<txp:author />' limit="1" />
.
Offline
#5 2020-09-22 10:43:52
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 162
Re: Show list of users who have already posted to a section
etc wrote #326005:
You can go another way: generate an authors list via
<txp:authors />
and check inside it for each author whether he has ‘Blog’ articles via<txp:article_custom author='<txp:author />' limit="1" />
.
If I understand correctly…
<txp:authors>
<txp:article_custom section="blog" author="<txp:author/>" limit="1">...</txp:article_custom>
</txp:authors>
That second way was not successful. The <txp:article_custom/>
tag needs the author’s name, while the <txp:authors/>
tag shows only RealName.
That way, I can’t make the article_custom
tag search for articles by the one generated by the <txp:authors/>
tag.
Offline
Re: Show list of users who have already posted to a section
Myusername wrote #326006:
That second way was not successful. The
<txp:article_custom/>
tag needs the author’s name, while the<txp:authors/>
tag shows only RealName.
Ah, sorry, then try
<txp:authors>
<txp:article_custom section="blog" author='<txp:author title="" escape="" />' limit="1">
...
</txp:article_custom>
</txp:authors>
I think the optimal way depends on article/author ratio and on what you need to output (authors data only or their articles too).
Offline
#7 2020-09-22 11:15:09
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 162
Re: Show list of users who have already posted to a section
etc wrote #326007:
I think the optimal way depends on article/author ratio and on what you need to output (authors data only or their articles too).
Ok … Thank you for your time and patience to show you how to do it
Offline
Re: Show list of users who have already posted to a section
It’s tempting, in the vein of this request, to add a fields
attribute to <txp:article(_custom) />
. Then, the OP problem could be solved as fast and furious
<txp:article_custom fields="DISTINCT AuthorID" section="blog" limit="999" break=",">
<txp:author />
</txp:article_custom>
Offline
Re: Show list of users who have already posted to a section
We are testing a new fields
attribute in 4.8.4. Its purpose is to extract only distinct fields
values from articles, additionally counting the number of articles matching these values. For example,
<txp:article_custom fields="AuthorID" section="blog" sort="count DESC" limit="10" wraptag="ol" break="li">
<txp:author /> has published <txp:yield item="count" /> articles.
</txp:article_custom>
outputs a list of authors having published in ‘blog’ section, ordered by the number of articles. Unlike the standard if_different
construction, it respects limit
and offset
attributes, thus such lists can be paginated.
I feel it’s a bit borderline between core and plugns, opinions welcome.
Offline