Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-04-13 01:15:50

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

"One year ago today"

Is there a way to get, say, article_custom to output whatever article matched today’s date minus-one year?


Yes, I have tried turning it off and on.

Offline

#2 2006-04-13 02:43:13

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: "One year ago today"

There is. This is just off the top of my head, I haven’t tested it, but it would be something along these lines:

<txp:php>
// find this year
$year = safe_strftime('%Y', false);

// take away 1 year
$year--;

// make the timestamp for this day last year
$when = mktime(0, 0, 0, 
	safe_strftime('%m', false), 
	safe_strftime('%d', false),
	$year
);

echo article_custom(array(
	'month' => safe_strftime('%Y-%m-%d', $when)
));
</txp:php>

Got the idea? If it doesn’t work I’m sure I or someone else can actually test it out and correct it as necessary.

Offline

#3 2006-04-13 22:43:50

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: "One year ago today"

wow… it works right out of the box; thanks! Unfortounately, I’m such a php dufus that I can’t even figure out how to add a form="name" to it.

Help?


Yes, I have tried turning it off and on.

Offline

#4 2006-04-14 00:43:51

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: "One year ago today"

nevermind, I got it:


echo article_custom(array(
	'month' => safe_strftime('%Y-%m-%d', $when),
	'form' => 'name'
));

thanks mucho, Mary!!

Last edited by alesh (2006-04-14 10:16:35)


Yes, I have tried turning it off and on.

Offline

#5 2006-04-14 10:14:29

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: "One year ago today"

Oh, oops . . . it returns null if there is no article with that exact date. Is a tweak possible that would show one article with date =< then today’s??


Yes, I have tried turning it off and on.

Offline

#6 2006-04-15 03:04:53

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: "One year ago today"

Sorry, show what instead (of nothing)?

Offline

#7 2006-04-15 16:31:14

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: "One year ago today"

uh . . . i was going to say ‘the article with the closest date’ but that’s stupid. Ideally, it would work like a regular article tag with a limit="1". So if it’s the 15th, and nothing has the date 4/15/05, then it goes to 4/14/05. In other words, it grabs the next oldest article.

Can that be done with some simple tweak of your code?


Yes, I have tried turning it off and on.

Offline

#8 2006-04-15 20:06:16

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: "One year ago today"

Possible? Yes. Simple? No. A simple update could, instead, show some predefined message/form/article, would that be sufficient?

Offline

#9 2006-04-17 05:02:56

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: "One year ago today"

Well, the article is preceeded by <p>One year ago today: <br/>, so I suppose some conditional code that would prevent that statement from printing if there was no article would work.

Am I correct in feeling a little frustration at the whole ‘txp:tag’ system? I am interested in learning php, and it seems like the tags are keeping me removed from the machinery more then is necessary. I’ve been helping a friend with a wordpress blog. Under that system, all the dynamic elements are expressed with php right there in the templates. It’s more difficult for the beginner, but it gets the user dealing with the “real” code sooner, so that when they figure it out they’re not limited, like txp users are by what the ‘tags’ can do.

I guess what I’m saying is that I’d like to figure out how to do this myself. I have programming background, and a php manual (wrote the image-randomization script on my site from scratch!) . . . where can I go to get help figuring out what I need about how textpattern works under the hood, short of spending weeks studying the code?


Yes, I have tried turning it off and on.

Offline

#10 2006-04-17 05:48:40

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: "One year ago today"

Am I correct in feeling a little frustration at the whole ‘txp:tag’ system? I am interested in learning php, and it seems like the tags are keeping me removed from the machinery more then is necessary… they’re not limited, like txp users are by what the ‘tags’ can do.

It’s a matter of personal taste. Some like it, some hate it, some are in between, and sometimes it depends upon the specific use.

What I do is usually turn larger amounts of php into a plugin, (which is harder than it sounds). I recommend you checkout Alex’s series of articles on the subject.

Here’s the meat of what this would look like in plugin form:

function ext_year_ago_today($atts)
{
	extract(lAtts(array(
		'form'            => '',
		'message'         => 'One year ago today:',
		'message_wraptag' => 'p',
	), $atts));

	if ($form)
	{
		// find this year
		$year = safe_strftime('%Y', false);

		// take away 1 year
		$year--;

		// make the timestamp for this day last year
			$when = mktime(0, 0, 0, 
			safe_strftime('%m', false), 
			safe_strftime('%d', false),
			$year
		);

		// find the article
		$article = article_custom(array(
			'month' => safe_strftime('%Y-%m-%d', $when),
			'form'  => $form
		));

		if ($article)
		{
			echo tag($message, $message_wraptag, '').$article;
		}
	}
}

The hardest part of a Textpattern plugin is the basic PHP itself, you’re not really limited. There are a bunch of “helper” functions available, which you can checkout in the “lib” folder (the filenames are deceptive as to the kinds of functions within them).

Offline

Board footer

Powered by FluxBB