Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Custom fields question
I am wondering if this is possible, here is my case.
I am making use of custom fields, one of which is named “created_by”, and it is used to output the author of an item (that is not a TXP author because they don’t have access to TXP). We would like to be able to somehow make a list of authors that have created the most items. In another words – output a list of the most frequently inserted words in the custom field created_by.
Is this even possible, or is there a plugin maybe? This seems to me like a long shot, but I thought I’d ask anyway. If someone has an idea for an alternative way to approach this – I’m all ears.
Offline
Re: Custom fields question
It’s possible and only requires a single SQL query to create a list of authors + the number of articles they wrote. Something like this perhaps (not tested):
<txp:php>
$rs = safe_rows(
'custom_1, count(*) AS nr',
'textpattern',
"Status >= 4 AND custom_1 != '' GROUP BY custom_1 ORDER BY nr DESC"
);
if ($rs)
{
echo '<ul>';
foreach($rs as $row)
{
extract($row);
echo '<li>'.escape_output($custom_1).' ('.$nr.')</li>';
}
echo '</ul>';
}
</txp:php>
Last edited by ruud (2007-09-19 10:39:38)
Offline
Re: Custom fields question
Wow ruud, that’s it! There is one small thing though – it outputs the field with nothing entered in the created_by custom field as the first one (because most articles don’t use that field). Is there a way around this?
Offline
Re: Custom fields question
Sure, I’ve modified the example above to deal with empty custom_1 fields.
Offline
Re: Custom fields question
Ridiculously awesome! Thanks so much ruud!
Offline
Pages: 1