Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2007-06-07 05:41:09
- mhulse
- Plugin Author
- From: Eugene Oregon
- Registered: 2005-01-21
- Posts: 200
[solved] Tags in Tags using PHP: The Gordian Knot?
<txp:wet_for_each_image category=“test”><txp:upm_image image_id=”{id}” type=“popup” /></txp:wet_for_each_image>
In reference to this great article
Could someone post an example of how to convert the above code to PHP for learning purposes?
I have no problems understanding how to implement something like:
<txp:php>
$a = custom_field(array(‘name’ => ‘Lightbox’));
$b = image_index(array(‘c’ => $a));
echo $b;
</txp:php>
Which, by the way, works great… But how do I script a nested tag, like in first code example?
Many thanks for the help. Just trying to learn how to break-in to the TXP syntax with PHP… I feel a bit more comfortable with PHP.
TIA! :)
Cheers,
m
Last edited by mhulse (2007-06-11 07:08:37)
Offline
Re: [solved] Tags in Tags using PHP: The Gordian Knot?
mhulse wrote:
But how do I script a nested tag, like in first code example?
You might want to investigate the plug-in asy_wondertag
TextPattern user since 04/04/04
Offline
#3 2007-06-07 06:02:41
- mhulse
- Plugin Author
- From: Eugene Oregon
- Registered: 2005-01-21
- Posts: 200
Re: [solved] Tags in Tags using PHP: The Gordian Knot?
reid wrote:
You might want to investigate the plug-in asy_wondertag
Hi Reid!
Thanks for the quick reply. :)
I actually just did, and it works great.
I guess I just would like to know how to do the PHP thing for learning purposes.
Thanks again for the reply and link.
Cheers,
Micky
Offline
#4 2007-06-07 07:36:31
- mhulse
- Plugin Author
- From: Eugene Oregon
- Registered: 2005-01-21
- Posts: 200
Re: [solved] Tags in Tags using PHP: The Gordian Knot?
A few more thoughts/questions… But first, an example:
<txp:asy_wondertag>
<txp:wet_for_each_image category=”<txp:custom_field name=“Lightbox” />” sort=“name asc”>
<!—<txp:upm_image form=“lightbox” image_id=”{id}” />—>
<txp:php>
$b = upm_image(array(‘form’ => “lightbox”, ‘image_id’ => ‘{id}’));
$n = explode(‘|’, $b);
print_r($n);
</txp:php>
</txp:wet_for_each_image>
</txp:asy_wondertag>
In above example, I think I would be able to solve my problem** if I were able to move the “wet_for_each_image” wrapping tag within the “txp:php” tags… Additionally, I would prefer to not use a plugin just to get the value out of a custom field — In other words, I will opt for just using a sprinkle of PHP to get the custom_field value vs. using the “asy_wondertag” plugin. Basically, once I figure out how to use PHP with the “wrapping” tags, I will be a happy mate.
Hehe, I did not realize that TXP made it so hard to use PHP to parse template tags. I am coming from the world of Expression Engine, and as much as I dislike many aspects of that templating engine, it sure does allow easy integration with PHP scripts.
**Problem: long story short, I am trying to produce one text link for a lightbox, vs showing all thumbs… I have a feeling PHP will help me solve this problem. Using this lightbox setup, I almost have the results I want.
Last edited by mhulse (2007-06-07 07:48:57)
Offline
Re: [solved] Tags in Tags using PHP: The Gordian Knot?
mhulse wrote:
<txp:wet_for_each_image category="test"><txp:upm_image image_id="{id}" type="popup" /></txp:wet_for_each_image>
In reference to this great article
Could someone post an example of how to convert the above code to PHP for learning purposes?
All contents which are embraced by a particular tag are passed to the tag handler function as a second parameter, this is a missing point in my article. So the snippet below would probably work (not tested, so it might lack a quote or a semicolon here and there):
<txp:php>
$thing = '<txp:upm_image image_id="{id}" type="popup" />'; #just pass it along literally
$atts = array('category' => 'test'); # pack all attributes into a dictionary array
echo wet_for_each_image ($atts, $thing);
</txp:php>
Last edited by wet (2007-06-07 07:49:18)
Offline
#6 2007-06-07 07:54:13
- mhulse
- Plugin Author
- From: Eugene Oregon
- Registered: 2005-01-21
- Posts: 200
Re: [solved] Tags in Tags using PHP: The Gordian Knot?
Wet! Many thanks for you reply!
And many thanks for your great forum posts and tutorials and code — you do top notch work!
Ahhh, pass it literally… Why did I not think of that! Your example makes it look easier than I had thought.
Thanks! :)
Have a great day/night,
Cheers,
Micky
Offline
#7 2007-06-07 10:04:22
- mhulse
- Plugin Author
- From: Eugene Oregon
- Registered: 2005-01-21
- Posts: 200
Re: [solved] Tags in Tags using PHP: The Gordian Knot?
Ah, cool… I think I got my problem(s) fixed… I dunno, but maybe it will help others:
<txp:if_custom_field name="Lightbox">
<txp:php>
# Hackish setup for lightbox setup. End result: one text link to display multiple lightbox images.
$cust = 'Lightbox'; // Custom field name.
$a = custom_field(array('name' => $cust)); // Get value from custom field.
$title = title(array()); // Get title. Pitfall: Textpattern tags without any attribute require an empty array for the tag handler function.
$thing = '<txp:upm_image form="lightbox" image_id="{id}" />|'; // String literal to be passed into wet_for_each_image() method.
$atts = array('category' => $a, 'sort' => 'name asc'); // Attributes for wet_for_each_image().
$result = wet_for_each_image($atts, $thing); // Call method, store in $result.
$parts = explode('|', $result); // Convert to array.
$junk = array_pop($parts); // Get rid of last key.
for($i = 0; $i < count($parts); $i++) {
$do = ($i > 0) ? 'display:none' : ''; // Only want to show the first link.
echo '<h3 style="'.$do.'"><a rel="lightbox['.$a.']" href="'.$parts[$i].'" title="Object: '.$title.'">'.$title.'</a></h3>'; // Output html.
}
</txp:php>
<txp:else />
<h3><a href="#"><txp:title /></a></h3>
</txp:if_custom_field>
<txp:body />
Long story short, using info from this great tutorial , I now have a working lightbox that uses only one link to show a series of related images. Nice!
Note: the above code could be waaaaaaaaaaaay more optimized… I plan on doing that some time in next few days… I can post more details if anyone wants to see the full setup (not that this is anything amazing, lol! Just feels nice to have accomplished something.)
Cheers,
Micky
Offline