Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-12-08 20:48:50

Gizmo
New Member
From: Prague, Czech Republic
Registered: 2012-03-07
Posts: 3
Website

Placeholder if not enough articles are in category

Hello,
I would like to get some placeholder, if not enough articles are in category.

Example:
I am using this tag to return 3 articles from specified category:
<txp:article_custom form=“name-of-my-own-article-form” limit=“3” category=“name-of-category” match=“Category2”/>

Sometimes, there are only 1 or 2 articles in that category. Is any way to display some other html content, instead of blank space?

What I need:
Article 1 | Article 2 | Article 3
or
Article 1 | Article 2 | Placeholder
or
Article 1 | Plaecholder | Placeholder

Thanks a lot!

Last edited by Gizmo (2018-12-08 20:49:29)

Offline

#2 2018-12-09 11:47:50

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,107
Website

Re: Placeholder if not enough articles are in category

Hi Gizmo, Here’s an untested solution

<txp:variable name="CountCategoryArticles"><txp:article_custom section="your_section" category="your_category" pageby="1" pgonly /></txp:variable>
<txp:if_variable name="CountCategoryArticles" value="">
no content
<txp:else />
<txp:if_variable name="CountCategoryArticles" value="1">
 Article 1 | Plaecholder | Placeholder
<txp:else />
<txp:if_variable name="CountCategoryArticles" value="2">
Article 1 | Article 2 | Placeholder
<txp:else />
Article 1 | Article 2 | Article 3
</txp:if_variable>
</txp:if_variable>
</txp:if_variable>

>Edited to add that there might be a way to do the above using the evaluate tag which I am yet to fully familiarise myself with it. It is these kind of real case questions though that may help in the implementation of the new tags.

Last edited by colak (2018-12-09 11:54:26)


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

Offline

#3 2018-12-09 15:01:59

etc
Developer
Registered: 2010-11-11
Posts: 3,106
Website

Re: Placeholder if not enough articles are in category

colak wrote #315524:

It is these kind of real case questions though that may help in the implementation of the new tags.

Yes, this is an interesting question, and the solutions are numerous, depending on what you need exactly.

  • If placeholder is kind of default article, you could simply create a placeholder category, add few articles with Posted='1970-01-01' (say) and call
<txp:article_custom limit="3" category="name-of-category, placeholder" ... />
  • or call three articles separately using offset attribute
<txp:article_custom limit="1" category="name-of-category" match="Category2">
    <txp:output_form form="name-of-my-own-article-form" />
<txp:else />
    Placeholder 1
</txp:article_custom>
<txp:article_custom limit="1" offset="1" category="name-of-category" match="Category2">
    <txp:output_form form="name-of-my-own-article-form" />
<txp:else />
    Placeholder 2
</txp:article_custom>
<txp:article_custom limit="1" offset="2" category="name-of-category" match="Category2">
    <txp:output_form form="name-of-my-own-article-form" />
<txp:else />
    Placeholder 3
</txp:article_custom>
  • or do like Yiannis suggests, with <txp:evaluate /> if you fancy
<txp:variable name="counter" value='<txp:article_custom category="name-of-category" match="Category2" pageby="1" pgonly />' />
<txp:article_custom limit="3" category="name-of-category" form="name-of-my-own-article-form" match="Category2" />
<txp:evaluate query='<txp:variable name="counter" /> < 1'>Placeholder 1</txp:evaluate>
<txp:evaluate query='<txp:variable name="counter" /> < 2'>Placeholder 2</txp:evaluate>
<txp:evaluate query='<txp:variable name="counter" /> < 3'>Placeholder 3</txp:evaluate>
  • or use a XML-manipulation plugin.

etc_[ query | search | pagination | date | tree | cache ]

Offline

#4 2018-12-09 16:50:15

Gizmo
New Member
From: Prague, Czech Republic
Registered: 2012-03-07
Posts: 3
Website

Re: Placeholder if not enough articles are in category

Thank you for your posts! I see there are a lot of options and of them looks good,
I’ll try some, I am sure it solves my problem.

Offline

Board footer

Powered by FluxBB