Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2017-08-01 17:49:25
- macosa
- New Member
- Registered: 2016-07-16
- Posts: 7
txp:article_custom via php echo
Hello!
Tryin’ to use <txp:php> instead of <txp:article_custom> but it doesnt work with custom fields. For example, if I use <txp:article_custom section=“losangeles” form=“listbar” Geolatitude=“33.747856” /> custom field “Geolatitude” with value “33.747856” is working and I see what I need. But if I use
<txp:php>
echo article_custom (array(
‘form’ => ‘listbar’,
‘section’ => ‘losangeles’,
‘Geolatitude’ => ‘33.747856’
));
</txp:php>
It will show me ALL articles from current section. Can somebody help me?
Last edited by macosa (2017-08-01 17:50:07)
Offline
Re: txp:article_custom via php echo
Hello,
try lowercase:
<txp:php>
echo article_custom (array( 'form' => 'listbar', 'section' => 'losangeles', 'geolatitude' => '33.747856'
));
</txp:php>
Offline
#3 2017-08-01 18:57:21
- macosa
- New Member
- Registered: 2016-07-16
- Posts: 7
Re: txp:article_custom via php echo
Hello!
Great. Simple)))) Yep. It’s workin. Thank You very much!!!
Offline
Re: txp:article_custom via php echo
Try a lower-case ‘g’ for ‘Geolatitude’ in the PHP version. Internally, it’s converted to lower-case when you use it as a tag, but in the PHP version there’s no auto-conversion applied.
EDIT: etc was faster on the keys…
Last edited by Bloke (2017-08-01 18:58:41)
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
#5 2017-08-01 19:01:39
- macosa
- New Member
- Registered: 2016-07-16
- Posts: 7
Re: txp:article_custom via php echo
Bloke, Thank you very much for explain of working of PHP! Did it
Last edited by macosa (2017-08-01 19:01:57)
Offline
Re: txp:article_custom via php echo
I would rather recommend more upgrade-proof
<txp:php>
echo parse('<txp:article_custom form="listbar" section="losangeles" Geolatitude="33.747856" />');
</txp:php>
Offline
#7 2017-08-02 16:38:06
- macosa
- New Member
- Registered: 2016-07-16
- Posts: 7
Re: txp:article_custom via php echo
etc,
Thank you,
But i need pure PHP and at next step to iterate over array and dont know is it possible or not. Do you know how to put it to foreach() or something like that?)))
I have one idea but it’s very bad for server and dont work))
- for ($geo = 33.4483; $geo <= $max_geolatitude; $geo = $geo + 0.0001) {
- echo article_custom (array(
- ‘form’ => ‘listbar’,
- ‘section’ => ‘losangeles’,
- ‘geolatitude’ => $geo
- ));
- }
it will not work cause step is very small i think. Do you have some ideas?
Last edited by macosa (2017-08-02 16:41:52)
Offline
Re: txp:article_custom via php echo
macosa wrote #306520:
But i need pure PHP and at next step to iterate over array and dont know is it possible or not. Do you know how to put it to foreach() or something like that?)))
You can switch to php inside article_custom
loop. Each article data is contained in global $thisarticle
:
<txp:article_custom section="losangeles" limit="999">
<txp:php>
global $thisarticle;
if ($thisarticle['geolattitude'] > 33.4483 && $thisarticle['geolattitude'] < 40)
{// do something}
</txp:php>
</txp:article>
This is sub-optimal, but currently you can not filter article_custom
by custom field ranges without a plugin. I suspect etc_query can help :-)
Offline
#9 2017-08-09 18:19:38
- macosa
- New Member
- Registered: 2016-07-16
- Posts: 7
Re: txp:article_custom via php echo
Thank You! Im building like this. Its great i think ))))
<txp:article_custom section="trips" limit="999" form="map_clusters">
<txp:php>
global $thisarticle;
if ($thisarticle['geolatitude'] > ($_GET['geolat'] - 4) && $thisarticle['geolongitude'] > ($_GET['geolong'] - 7) && $thisarticle['geolatitude'] < ($_GET['geolat'] + 4) && $thisarticle['geolongitude'] < ($_GET['geolong'] + 7)) {
echo article_custom (array(
'form' => 'map_clusters',
'section' => 'trips',
'geolatitude' => $thisarticle['geolatitude'],
'geolongitude' => $thisarticle['geolongitude']
));
}
</txp:php>
</txp:article>
Last edited by colak (2017-08-09 18:23:48)
Offline
Re: txp:article_custom via php echo
Hi macosa,
I edited your post above to show it as code. Click the edit button to see the textile required and do visit txstyle.org which can guide you though the markdown language.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: txp:article_custom via php echo
macosa wrote #306558:
Thank You! Im building like this. Its great i think ))))
Not yet, I think this should do what you need faster:
<txp:article_custom section="trips" limit="999">
<txp:php>
global $thisarticle;
if (abs($thisarticle['geolatitude'] - $_GET['geolat']) < 4 && abs($thisarticle['geolongitude'] - $_GET['geolong']) < 7) {
echo output_form (array('form' => 'map_clusters'));
}
</txp:php>
</txp:article_custom>
Offline
Re: txp:article_custom via php echo
Hello!
Is there any way to make txp:article_custom work with url ? Something like this:
<txp:article_custom url="page.html" />
I assume it can be done using the url field somehow through php?
Last edited by zenman (2017-08-28 16:04:35)
Offline