Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-11-15 15:18:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,911
Website

detect front page of section

I am trying to detect the front page of a section and the code does not seem to work. Am I using the wrong parameter for the variable?

<txp:variable name="front"><txp:page_url type="pg" /></txp:variable>
<txp:if_variable name="front" value="">
<txp:article status="sticky" limit="20" />
<txp:else /></txp:if_variable>
<txp:article limit="10" />

What I would expect to see from the above is sticky articles in the beginning of the section’s front page, then 10 live articles.
On the other pages of the section’s list of articles I am indeed getting the articles as expected.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#2 2018-11-15 17:13:28

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,159
Website

Re: detect front page of section

What does <txp:page_url type="pg" /> give you if you use it on its own on the desired page?

Phil uses the equivalent of <txp:if_variable name="front" value="1"> in the four-point-seven theme here.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2018-11-15 17:48:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: detect front page of section

Yes, use value="1" to test.

Alternatively, in 4.7+ this might do something similar without the variable dance:

<txp:if_article_list>
   <txp:evaluate query='<txp:page_url type="pg" /> = 1'>
      <txp:article status="sticky" limit="20" />
   </txp:evaluate>
   <txp:article limit="10" />
</txp:if_article_list>

Note the <txp:if_article_list>, otherwise you’d see the same behaviour on an individual article page because pg is set to 1 there too. Of course, if you have a different template serving the landing page vs individual articles, you can omit the wrapped conditional.

Last edited by Bloke (2018-11-15 17:51:08)


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

#4 2018-11-15 17:51:53

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,911
Website

Re: detect front page of section

On the rescue again!!! Thanks so much Julian. That did the trick.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#5 2018-11-15 18:18:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,911
Website

Re: detect front page of section

Sorry Stef,

I just saw your post. Thank you too.

ps… edited to add that I am really getting to like the eavluate tag!

Last edited by colak (2018-11-15 18:40:03)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

Board footer

Powered by FluxBB