Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-09-18 15:50:31

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

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

#2 2007-09-18 17:57:59

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#3 2007-09-19 10:29:39

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

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

#4 2007-09-19 10:41:33

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Custom fields question

Sure, I’ve modified the example above to deal with empty custom_1 fields.

Offline

#5 2007-09-19 10:45:46

draganbabic
Member
From: Novi Sad, Serbia
Registered: 2006-09-27
Posts: 118
Website

Re: Custom fields question

Ridiculously awesome! Thanks so much ruud!

Offline

Board footer

Powered by FluxBB