Page 1 of 1
nested php tags? easy for you, hard for a noob ;)
Posted: Tue Nov 23, 2010 1:17 pm
by sanknyc
hi there,
noob php guy here... i know what the issue is - just cant find an answer because most searches for "nested php tags" are about if statements... not what i'm after...
this is for a wordpress site, where an audio player plays an mp3:
Code: Select all
<?php if (function_exists("insert_audio_player")) { insert_audio_player("[audio:http://www.mysite.com/path/to/<?php getCustomField('mp3'); ?>.mp3]"); } ?>
should return:
[audio:
http://www.mysite.com/path/to/track.mp3]
(which is referenced by the audio player...)
i know i'm not allowed to have more than one "php" tag in a string but trying echo kept putting the getCustomField reference outside the url string, so the player couldn't find the mp3 since the resulting url was always just "
http://www.mysite.com/path/to/"
i know it's an easy one, hoping for some help soon!
thanks!
s
Re: nested php tags? easy for you, hard for a noob ;)
Posted: Tue Nov 23, 2010 2:06 pm
by Neilos
Maybe;
Code: Select all
<?php
$mp3 = getCustomField('mp3');
$string = "audio:http://www.mysite.com/path/to/";
$string .= $mp3;
$string .= ".mp3";
if (function_exists("insert_audio_player")) {
insert_audio_player($string);
}
?>
Or even just leave the php tags out, (don't know if this works)
Code: Select all
<?php if (function_exists("insert_audio_player")) { insert_audio_player("[audio:http://www.mysite.com/path/to/" . getCustomField('mp3') . ".mp3]"); } ?>
I haven't tried either of these two so the prob won't work straight off the bat but you'll get the idea and be able to make them work
Re: nested php tags? easy for you, hard for a noob ;)
Posted: Tue Nov 23, 2010 3:51 pm
by sanknyc
hi there
thanks for the quick response!
tried both options out and while they do make sense, they both simply have the output from the wordpress field next to the player... in other words the mp3 player is indeed injected but the variable of the mp3 name is rendered as text outside the url string...
at least the variable is being read, now just have to get it within the url...
i know you said they'd only work with some tweaking but still stuck on how to get the mp3 name into the url...
s
Re: nested php tags? easy for you, hard for a noob ;)
Posted: Tue Nov 23, 2010 6:59 pm
by Neilos
I'm not familiar with wordpress and the function insert_audio_player() and I'm not sure I understand your problem correctly. lol.
So here goes... Are you storing the name of the mp3 in the $mp3 variable? In other words what is shown if you echo $mp3? Is it the name of the mp3?
If you are getting the name of the mp3 stored in the variable $mp3 then;
Code: Select all
$string = "audio:http://www.mysite.com/path/to/";
$string .= $mp3;
$string .= ".mp3";
will concatenate the strings to produce the URL you require.
As for how you then use this URL with the insert_audio_player() function I do not know. You'll need to check the documentation for that.
Another thought, for these wordpress functions are you including them in your script? If not then your script will have no idea what insert_audio_player() or getCustomField() are.
Re: nested php tags? easy for you, hard for a noob ;)
Posted: Thu Nov 25, 2010 1:50 pm
by sanknyc
hi there,
thanks again for the response. much appreciated....
ok, the ".mp3]" section may be a bit misleading... that doesn't have to be there... it's simply the actual .mp3 extension that i'm adding in the string so the client doesn't have to type that into the field when they are injecting the name of the mp3 file into the script.
the other "mp3" part is the real cookie : <?php getCustomField('mp3'); ?>
this is calling the data from the corresponding custom field in the backend that houses the mp3 file name only.
the insert_audio_player() function is part of the functions from the WPaudioPlayer plugin, so it indeed does work (showing the player on the output page), but the name of the variable mp3 name coming from the custom field are being rendered outside the url string...
hope that makes sense... does it being any new insights?
thanks!
s