Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-04-25 15:19:31

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

[SOLVED] conditionals, sticky, and other single articles in a section

Time for my public shaming in the community square, again. Seems like every time I want to do something that should be like breathing air at this point, I can’t get it right after trying every way to Sunday. (And, once again, examples in the tag docs don’t help me. Someday I’ll learn to do something about that.)

  1. I have a section.
  2. I have a sticky article for that section.
  3. I have 2 other articles assigned to that section.
  4. When someone clicks the section link, I want the sticky to show.
  5. …else…
  6. When one of the other two article links are clicked I want that respective article to show.
  7. There will never be more than one article showing at a time in this section.

What is the simple markup for that?

No, I won’t give an example. It’s already humiliating.

Offline

#2 2018-04-25 15:42:26

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

Re: [SOLVED] conditionals, sticky, and other single articles in a section

Hi Destry,

I had the same problem a few days ago. Here is how I dealt with it and here is Julian’s advice re the search results, implemented in the code above.

You should of course change <txp:article_custom id="1"> to <txp:article_custom id="##" status="sticky">.


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

Offline

#3 2018-04-25 16:07:11

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [SOLVED] conditionals, sticky, and other single articles in a section

lol … I’ll need a slightly more stripped down example. I’m not concerned about search. I just want the absolutely bare-bones markup to accomplish items 4-6 above.

Okay, just looked at Julian’s lines… still seems a little more complicated than what I’m trying to do, so I’m guessing it’s not the same thing.

Either that or there’s a failing with tags to do something that would otherwise seem so basic.

Last edited by Destry (2018-04-25 16:15:19)

Offline

#4 2018-04-25 16:20:58

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

Re: [SOLVED] conditionals, sticky, and other single articles in a section

Try something like

<txp:if_article_list>
<txp:if_article_section section="your_section">
<txp:article_custom id="##" status="sticky" />
<txp:else />
<txp:hide>you are in some other section</txp:hide>
<txp:article />
</txp:if_article_section>
<txp:else />
<txp:hide>you are in an individual article</txp:hide>
<txp:article />
</txp:if_article_list>

> Edited to make the code more readable

Last edited by colak (2018-04-25 16:28:53)


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

Offline

#5 2018-04-25 16:35:55

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [SOLVED] conditionals, sticky, and other single articles in a section

That at least gets the sticky article to display, which contains links to the other two articles, but when I click those links, I just get a blank page.

Regardless, I don’t understand that tag structure at all. We have to wrap an if_article_list around an if_article_section and use article_custom with both id="" and status=""?

So much for section context, eh?

That’s why I can’t figure it out, I guess, it doesn’t seem logical.

This is the kind of thing my brain wants to do, but it doesn’t work…

<txp:if_article_id id="3">
   <h1><txp:title /></h1>
   <txp:body escape="trim,tidy" />
<txp:else />
   <txp:article form="simple_article" limit="1" />
</txp:if_article_id>

That just outputs the latest article in the section, even on default section context, which is completely wrong. But it seems like it should work from an section context point of view.

By they way, I’m putting this directly into a page template dedicated to this section, which is why I don’t get why context doesn’t work here.

Offline

#6 2018-04-25 16:42:26

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

Re: [SOLVED] conditionals, sticky, and other single articles in a section

Ok… got it now…

If you want to make it really simple create a separate template (page) for your section. Make sure that your section points to it in presentation>sections.

You can then just have

<txp:if_article_list>
<txp:article_custom id="3" status="sticky">
<h1><txp:title /></h1>
<txp:body escape="trim,tidy" />
</txp:article_custom>
<txp:else />
<txp:hide>you are in an individual article</txp:hide>
<txp:article form="simple_article" />
</txp:if_article_list>

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

Offline

#7 2018-04-25 16:52:12

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,611
Website

Re: [SOLVED] conditionals, sticky, and other single articles in a section

Destry wrote #311409:

That at least gets the sticky article to display, which contains links to the other two articles, but when I click those links, I just get a blank page.

That was the crucial bit of missing information.

By they way, I’m putting this directly into a page template dedicated to this section…

And that’s good to know too!

You should simply be able to do:

<txp:if_article_list>
    <txp:article status="sticky" form="simple_article" />
<txp:else />
    <txp:article status="live" form="simple_article" />
</txp:if_article_list>

If you want to be dead sure you get only one sticky article, you can add limit="1" to your status="sticky" variant. If it doesn’t show quite as you want, you might have to use listform="simple_article" (I’ve forgotten what it does if you specify just one attribute). You don’t strictly need status="live" as it is the default, but it is clearer when you come to look at it later.

That should show you only sticky articles on the landing page and render live articles on an individual article list. As your links to your live articles are in the body of your sticky article, you don’t have to cater for the links to the individual articles in your page template.


TXP Builders – finely-crafted code, design and txp

Offline

#8 2018-04-25 17:01:31

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [SOLVED] conditionals, sticky, and other single articles in a section

Same thing happens. I get the sticky okay, but when I try to click one of the other two articles, it’s just a blank page.

Don’t worry about it. I’ve decided to go back to a single article. I’ll just use anchors to point to the sections instead of individual article URLs. Not as classy, but at least it works, and all policies are in one place.

Oh, didn’t see your post, Julian, I’ll try that.

Last edited by Destry (2018-04-25 17:03:27)

Offline

#9 2018-04-25 17:14:11

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: [SOLVED] conditionals, sticky, and other single articles in a section

Unfortunately I lose the sticky output with that too.

I don’t get it.

Maybe time to step away from the screen awhile.

I’ll look at this again tomorrow. Must cook the dinner.

Offline

#10 2018-04-25 18:00:02

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

Re: [SOLVED] conditionals, sticky, and other single articles in a section

After dinner, do put it on debug mode as it might give you some clues.

I’ll just mention 2 things here

  1. Make sure your section is pointing to the template (page) in presentation>sections
  2. Make sure all articles which should belong to that section actually do belong to it (under write>articles)

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 2018-04-25 18:02:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,611
Website

Re: [SOLVED] conditionals, sticky, and other single articles in a section

I just tested* it on a clean setup and it worked. Maybe it’s something else:

  • check that your sticky article is set to sticky and on the right section
  • your live articles are set to live and are assigned to the right section
  • your links to the live articles in the body of the sticky article also have the right section in the link

- – -

Here’s my test:

A standard installation:

1. Duplicate the default page template and call it sticky-live-cascade.
2. Create a new section called test-section and assign sticky-live-cascade as the page template.
3. Edit the page template sticky-live-cascade and replace <txp:article limit="5" /> about two-thirds down with:

<txp:if_article_list>
    <txp:article status="sticky" limit="1" />
<txp:else />
    <txp:article />
</txp:if_article_list>

and save.

4. Now create three articles:

  • title = Live Article 1, section = test-section, status = live, content = “This is live article 1”
  • title = Live Article 2, section = test-section, status = live, content = “This is live article 2”
  • title = Sticky Article, section = test-section, status = sticky, content =

This is a sticky article with two links to live articles:

* "Live Article 1":/test-section/live-article-1
* "Live Article 2":/test-section/live-article-2

Then visit the front end and click on the section Test section in the menu. On:

  • domain.com/test-section/ -> The sticky article only with the two links
  • domain.com/test-section/live-article-1 -> Live Article 1
  • domain.com/test-section/live-article-2 -> Live Article 2
  • domain.com/test-section/sticky-article -> blank page (but this page is never linked to)

I set to debugging and looked at the trace and the sticky article on the landing page uses the default template as standard. So you should be fine with form="simple_article" in your example.

EDIT: Yiannis: Great minds … :-)


TXP Builders – finely-crafted code, design and txp

Offline

#12 2018-04-25 18:52:33

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

Re: [SOLVED] conditionals, sticky, and other single articles in a section

I just remembered something that Destry wrote some time ago but I do not know if it is relevant to this site.

Am I right that you use just the title in the url schema? ie site.tld/title? In such case I am not sure how the txp mechanism will recognise the section of an individual article.

jakob wrote #311416:

EDIT: Yiannis: Great minds … :-)

indeed:) But we both must be doing something wrong as Destry’s experiment is not fully working yet.

Last edited by colak (2018-04-25 18:55:44)


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

Offline

Board footer

Powered by FluxBB