Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-06-18 00:54:53
- nemozob
- Member
- Registered: 2008-04-15
- Posts: 36
Display list of authors with their article count?
Trying to output a list of all authors contributing to a blog and list their article count. I can hardcode the names but I would still need to dynamically pull the number of articles they wrote.
Looked for a plug-in but so far only found ones that live inside an article.
Offline
Re: Display list of authors with their article count?
If you were going with hardcoded names, you could use jmd_count. The following makes more sense however:
<txp:php>
$rs = safe_rows('count(*) as total, AuthorID', 'textpattern',
'Status=4 group by AuthorID');
if ($rs)
{
foreach ($rs as $row)
{
if ($row['total'] > 1)
{
$txt = 'articles';
}
else
{
$txt = 'article';
}
$realName = get_author_name($row['AuthorID']);
echo <<<EOD
<li>
{$realName} – {$row['total']} {$txt}
</li>
EOD;
}
}
</txp:php>
Edit: Added $txt
in, so ‘article’ will display for authors with only one article posted. Authors without any live articles posted will not be included (Status=4
).
Last edited by jm (2008-06-18 02:13:11)
Offline
Re: Display list of authors with their article count?
At first I thought rss_author_info did this but I guess it doesn’t?
I’d like this count functionality but also a link to the authors website. (which is currently hardcoded)
Last edited by MattD (2008-06-18 16:13:14)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
#4 2008-06-18 16:23:04
- nemozob
- Member
- Registered: 2008-04-15
- Posts: 36
Re: Display list of authors with their article count?
Thank you for the PHP, this worked great.
I forgot to ask if the author names could also be links to the authors articles. Is that possible?
Offline
#5 2008-06-18 16:32:38
- nemozob
- Member
- Registered: 2008-04-15
- Posts: 36
Re: Display list of authors with their article count?
Nevermind, I believe I have it working using
@
<ul>
<txp:php>
$rs = safe_rows(‘count(*) as total, AuthorID’, ‘textpattern’,
‘Status=4 group by AuthorID’);
if ($rs)
{
foreach ($rs as $row)
{
Offline
#6 2009-05-11 17:33:06
- M_i
- Member
- Registered: 2006-03-05
- Posts: 122
Re: Display list of authors with their article count?
Now how would I go about also listing registered authors with zero articles?
(I use the mem_self_register plugin, and periodically want to weed out unused accounts.)
Offline
Re: Display list of authors with their article count?
I think smd_query is better solution
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
#8 2009-05-12 07:19:00
- M_i
- Member
- Registered: 2006-03-05
- Posts: 122
Re: Display list of authors with their article count?
the_ghost wrote:
I think smd_query is better solution
Ok, but then what sort of query would you use to produce a list of all registered authors, including those with no articles, with the number of articles they posted?
Offline
Re: Display list of authors with their article count?
M_i wrote:
list of all registered authors, including those with no articles, with the number of articles they posted?
Something like…
<txp:smd_query query="SELECT name, count(Title) AS num_articles FROM txp_users LEFT JOIN textpattern ON name = AuthorID GROUP BY name">
Author: {name} ({num_articles})
</txp:smd_query>
??
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
#10 2009-05-12 11:48:50
- M_i
- Member
- Registered: 2006-03-05
- Posts: 122
Re: Display list of authors with their article count?
Bloke wrote:
Something like…
That’s brilliant! Thank you so much!
Offline