Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-11-16 13:20:27

helsinkifrostbites
Member
From: Ystad, Sweden
Registered: 2007-11-16
Posts: 47
Website

output number of articles by author in last 30 days?

I’m putting together a multi-user blog thing, and one of the requirements is to display the number of posts each user has made in the last 30 days.

I can get the total number of posts for each user with the rss_author_info plugin, but I really need to restrict that to the last 30 days only. Been trying to find a way for a few days now without success.

I’m a bit of a n00b at php, but I can struggle my way through code if need be. I just don’t know where to start with this.

Any ideas? Greatly appreciated.

Offline

#2 2007-11-17 16:59:35

ultramega
Member
Registered: 2006-02-26
Posts: 221

Re: output number of articles by author in last 30 days?

I can’t give you straight answer, but check

txp:if_author

and

Archive lists by month

What I’m thinking is you could maybe filter authors, then create monthly list for her/him, then move to next author…. Something like that maybe?

Offline

#3 2007-11-17 17:19:37

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

Re: output number of articles by author in last 30 days?

Something like this perhaps (not tested):

<txp:php>
  global $author;
  echo intval(safe_count('textpattern', "DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Posted AND authorid='".doSlash($author)."'"));
</txp:php>

Last edited by ruud (2007-11-17 22:10:08)

Offline

#4 2007-11-17 22:06:49

helsinkifrostbites
Member
From: Ystad, Sweden
Registered: 2007-11-16
Posts: 47
Website

Re: output number of articles by author in last 30 days?

ah- no, I get this:
Parse error: syntax error, unexpected ‘=’ in mysite/textpattern/publish/taghandlers.php(2738) : eval()’d code on line 3

Offline

#5 2007-11-17 22:10:28

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

Re: output number of articles by author in last 30 days?

remove the = after the echo (code update above)

Offline

#6 2007-11-17 23:05:33

helsinkifrostbites
Member
From: Ystad, Sweden
Registered: 2007-11-16
Posts: 47
Website

Re: output number of articles by author in last 30 days?

argh, no, now i get this:
Warning: Unexpected character in input: ‘’‘ (ASCII=39) state=1 in /customers/hfb-projekt.se/hfb-projekt.se/httpd.www/culinaria/textpattern/publish/taghandlers.php(2738) : eval()’d code on line 3

Parse error: syntax error, unexpected ‘"’ in /customers/hfb-projekt.se/hfb-projekt.se/httpd.www/culinaria/textpattern/publish/taghandlers.php(2738) : eval()’d code on line 3

Offline

#7 2007-11-17 23:49:02

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

Re: output number of articles by author in last 30 days?

Oops, corrected a wrong quote (code updated)

Offline

#8 2007-11-18 01:19:48

helsinkifrostbites
Member
From: Ystad, Sweden
Registered: 2007-11-16
Posts: 47
Website

Re: output number of articles by author in last 30 days?

well that doesn’t seem right either. because now I get 0 posts total.

Offline

#9 2007-11-18 10:50:56

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

Re: output number of articles by author in last 30 days?

Are you using this on an author page or in an article list or individual article page? If you’re using it outside an author page, replace global $author with global $thisarticle and replace $author (in the SQL query) with thisarticle['authorid'].

Offline

#10 2007-11-18 11:04:00

helsinkifrostbites
Member
From: Ystad, Sweden
Registered: 2007-11-16
Posts: 47
Website

Re: output number of articles by author in last 30 days?

Ok, I think I may have solved this by modifying the rss_author_info plugin.
what used to be:

function rss_author_info_postcount($atts) {
	global $thisarticle;
	if (is_array($atts)) extract($atts);
	$username = $thisarticle['authorid'];

	$query = "SELECT count(*) as posts from ".PFX."textpattern where authorid ='".$username."'";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 1) {
		return mysql_result($result,0,"posts");
	} else {
		return 0;
	}
}

now looks like this:

function rss_author_info_postcount($atts) {
	global $thisarticle;
	if (is_array($atts)) extract($atts);
	$username = $thisarticle['authorid'];

	$query = "SELECT count(*) as posts from ".PFX."textpattern where authorid ='".$username."' AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Posted";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 1) {
		return mysql_result($result,0,"posts");
	} else {
		return 0;
	}
}

Seems to be outputting the right number.
Now I just need to find a way to test that posts older than 30 days are really excluded…

Thanks a lot for your help, ruud.

Last edited by ruud (2007-11-18 11:54:16)

Offline

Board footer

Powered by FluxBB