Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#2 2017-08-01 18:53:12

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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

#4 2017-08-01 18:58:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,499
Website GitHub

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.

Hire 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

#6 2017-08-01 19:03:26

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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

#8 2017-08-02 19:02:21

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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

#10 2017-08-09 18:28:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

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

#11 2017-08-09 20:38:36

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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

#12 2017-08-28 16:00:28

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

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

#13 2017-08-28 16:50:29

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

Re: txp:article_custom via php echo

zenman wrote #306742:

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?

Hi zenman and welcome to txp.

The short answer to your question is No.

You can however, if the url you wish to show is part of the txp database, use: <txp:article_custom id="45" /> – You have to of course replace the id number to the id you wish to parse. You can read more about the article custom tag in the documentation.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#14 2017-08-28 16:58:54

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

Re: txp:article_custom via php echo

colak wrote #306743:

Hi zenman and welcome to txp.

The short answer to your question is No.

You can however, if the url you wish to show is part of the txp database, use: <txp:article_custom id="45" /> – You have to of course replace the id number to the id you wish to parse. You can read more about the article custom tag in the documentation.

Thanx. Oh, how sad. Yes, I know about Article_ID. Is there any other way I can get an article by its url?

Last edited by zenman (2017-08-28 17:01:35)

Offline

#15 2017-08-28 19:49:16

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,319

Re: txp:article_custom via php echo

zenman wrote #306744:

Is there any other way I can get an article by its url?

Could you describe a little what you want to achieve and why you think the best way to do this is via article URL? Maybe someone could offer some other way to solve it. E.g. if you want to use a URL parameter to call an article, then you might want to have a look at adi_gps.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB