Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-11-23 06:00:17

accarter
Member
From: Los Angeles
Registered: 2007-08-31
Posts: 31
Website

php in pages

Hi, I’m moving elements of a friend’s site into textpattern for him. In the original he has a sweet bit of code that calls up random images from a website. The code is:

<?
		rand(0,1)?$cat='pf':$cat='rw';
		$cat=='pf'?$imgno=rand(1,40):$imgno=rand(1,50);
		if($imgno<10){$imgno="0".$imgno;}
		?>

		<a href="http://whom.co.uk/squelch/">
		<img 	style="max-width: 125px; max-height: 125px;" 
			border="0";
			alt="!&#*%($"
			src="http://whom.co.uk/squelch/<?="$cat$imgno.jpg"?>" 
		/>
		</a>

and works at
http://eohippuslabs.com/dev/ (the image/link shows up in the footer).

When I include it in the page all i get is the alt text; when I include it in a form I get the same thing. I tried using the <txp:php> tag and housing the code in a form but, honestly, I don’t know php; here’s what I ended up with (cringe):

<txp:php>
		rand(0,1)?$cat='pf':$cat='rw';
		$cat=='pf'?$imgno=rand(1,40):$imgno=rand(1,50);
		if($imgno<10){$imgno="0".$imgno;}
		</txp:php>

		<a href="http://whom.co.uk/squelch/">
		<img 	style="max-width: 125px; max-height: 125px;" 
			border="0";
			alt="!&#*%($"
			src="http://whom.co.uk/squelch/<txp:php>="$cat$imgno.jpg"</txp:php" 
		/>
		</a>

I’m trying to figure it out on the error page; for example: http://eohippuslabs.com/boo
Any help would be greatly appreciated.
Thank you so much!
All the best,
Allison

(edited to display code properly. -Els)

Last edited by els (2007-11-23 14:28:33)

Offline

#2 2007-11-23 06:13:48

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

Re: php in pages

FAQ

Offline

#3 2007-11-23 06:21:11

accarter
Member
From: Los Angeles
Registered: 2007-08-31
Posts: 31
Website

Re: php in pages

thank you! I actually already looked at that – I still don’t understand is if this means that php embedded in html – for example inside an img src tag – would be impossible in textpattern.

Offline

#4 2007-11-23 09:08:07

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: php in pages

In example this would work – in theory, and it really small theory.

<txp:php>
	rand(0,1) ? $cat='pf' : $cat = 'rw';
	$cat == 'pf' ? $imgno = rand(1,40) : $imgno = rand(1,50);
	if($imgno<10){
		$imgno='0'.$imgno;
	}
	echo '<a href="http://whom.co.uk/squelch/">';
	echo '<img style="max-width: 125px; max-height: 125px;" border="0" alt="!&#*%($"';
	echo 'src="http://whom.co.uk/squelch/'.$cat.$imgno.jpg.'" /></a>';
</txp:php>

But if it only produces random image, why not using a plugin? That would be much more easier to control and master.

Cheers!

Last edited by Gocom (2007-11-23 09:10:54)

Offline

#5 2007-11-23 09:30:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,449
Website GitHub

Re: php in pages

accarter wrote:

he has a sweet bit of code that calls up random images from a website… When I include it in the page all i get is the alt text

Odd. Maybe it’s an issue with not being allowed to hotlink?

Gocom wrote:

But if it only produces random image, why not using a plugin?

Good idea! But only if the images can be stored locally within TXP (which is preferable) instead of hotlinked. Hmm, let me see… how about… erm… ooh smd_random_banner :-)

Last edited by Bloke (2007-11-23 09:30:54)


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

Offline

#6 2007-11-23 15:49:53

accarter
Member
From: Los Angeles
Registered: 2007-08-31
Posts: 31
Website

Re: php in pages

Thank you!!
The images aren’t local and can’t be for some conceptual reason I’m not privy to, so no plugin for me.

Offline

#7 2007-12-14 01:06:18

drichert
New Member
Registered: 2007-12-13
Posts: 1

Re: php in pages

Hello. I’m the guy. Here’s what I ended up changing it to (similar to Gocom’s suggestion) to make it work with textpattern (and make it a bit more readable). Looks like textpattern doesn’t support <?=$val?> style PHP tags.

<txp:php>
if(rand(0,1)){ 
    $cat = 'pf'; 
}else{
    $cat = 'rw';
}
if($cat=='pf'){
    $imgno = rand(1,40);
}else{
    $imgno = rand(1,50);
}
if($imgno < 10){
    $imgno= "0" . $imgno;
}
echo '<a href="http://whom.co.uk/squelch/">' . "\n";
echo '<img style="max-width: 125px; max-height: 125px;" border="0"' . "\n";
echo 'src="http://whom.co.uk/squelch/'. $cat . $imgno . '.jpg" />'."\n";
echo '</a>'."\n";
</txp:php>

Offline

Board footer

Powered by FluxBB