Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » How?
  3. » Section image?

#1 2021-04-14 17:19:28

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 660
Website

Section image?

Is there something like a <txp:section_image /> for instance overriding a given article image as soon as the section doesn’t display an individual article?

Thanx for any hints.

Last edited by jayrope (2021-04-14 17:20:02)


a hole turned upside down is a dome, when there’s also gravity.

Offline

#2 2021-04-14 17:50:02

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,305
Website GitHub

Re: Section image?

No because there’s no concept of an image attached to a section. But you could do it in a few ways by hijacking existing fields. Maybe in the section Description you could put an image tag or an image ID? Then grab it with the meta_description tag, with escape="" as required.

Alternatively if you’re using 4.8.5 you could take advantage of the <txp:images> tag’s ability to use <txp:else />. So in your individual article you can choose between an article image if there is one or a different image if there isn’t.

If you’re trying to do this at the level above this (i.e. if you’re on a section landing page) then there won’t be an individual article at all so you’ve nothing to test. In that case you’ll have to rely on stashing an image tag or ID – either in the section definition itself somewhere, or in one or more variables that are included on the page. Then you can test <txp:if_article_list> and display your image if so, otherwise display your individual article as normal.

Plenty of ways to approach it. Up to you which one works best in your situation.


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

Online

#3 2021-04-14 21:58:33

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

Re: Section image?

jayrope wrote #329823:

Is there something like a <txp:section_image /> for instance overriding a given article image as soon as the section doesn’t display an individual article?

There’s also jcr_section_custom with which you can add a field with your own name, e.g. section_image (i.e. instead of hijacking meta_description). Place your image id in there.

<txp:if_article_list>
    <txp:images id='<txp:jcr_section_custom name="section_image" />' limit="1">
        <txp:image />
    </txp:images>
</txp:if_article_list>
Bloke wrote #329824:

Plenty of ways to approach it. Up to you which one works best in your situation.

Another way is to name your image to match your section name, e.g. header-image-mysection.jpg and then do:

<txp:if_article_list>
    <txp:images name='header-image-<txp:section />.jpg'>
        <txp:image />
    </txp:images>
</txp:if_article_list>

No extra fields required, but you do need to remember to ensure the names match should you change the section name or update the image in future.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2021-04-14 23:24:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,305
Website GitHub

Re: Section image?

jakob wrote #329825:

Another way is to name your image to match your section name

Ah yes, good addition. I’ve used that before and it works well. And the great thing about that is that from 4.8.5 you can use <txp:else /> as part of the <txp:images> to display a default image if there isn’t a dedicated section image.


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

Online

#5 2021-04-16 15:19:55

agovella
Member
From: Houston, TX
Registered: 2005-05-01
Posts: 48
Website Twitter

Re: Section image?

You can use an article’s image to display an image for a Section. set the article to Sticky and display one sticky article on the Section page. That will pull up the one article with the image you want.

Offline

#6 2021-04-18 13:53:53

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 660
Website

Re: Section image?

Thank you everyone for your suggestions. Thinking them through, probably leading to implement a method, which needs the least commenting of code or memory for image names. Thank you again.


a hole turned upside down is a dome, when there’s also gravity.

Offline

  1. Index
  2. » How?
  3. » Section image?

Board footer

Powered by FluxBB