Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-10-31 19:28:32

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Display "sorry..." after an if_category search if no articles exist

Maybe it has been answered before but I can’t find a solution to this small problem:
in the default archive page we have this

<!-- else is this an article category list? -->
        <txp:if_category>
          <h2><txp:text item="category" />: <txp:category title="1" /></h2>
            <txp:article form="article_list" />

        <!-- else display articles normally -->

I’m using it in a section context and it correctly performs a search in that category, but it just displays the category title with an empty list if articles do not exist within the category.
I cannot get a simple way (if different/if variable…) to display a message “sorry, no articles in this category at the moment…”

Any idea?

(edited for better code display. -Els)

Last edited by els (2011-10-31 19:44:09)

Offline

#2 2011-10-31 19:51:16

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display "sorry..." after an if_category search if no articles exist

<txp:if_category>
   <txp:variable name="hasarticles" value='<txp:article limit="1">yes, an article!</txp:article>' />
   <txp:if_variable name="hasarticles" value="">
      <p>Sorry, no articles!</p>
   <txp:else />
      <h2><txp:text item="category" />: <txp:category title="1" /></h2>
      <txp:article form="article_list" />
   </txp:if_variable>
</txp:if_category>

Offline

#3 2011-10-31 20:45:27

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Display "sorry..." after an if_category search if no articles exist

Fast, simple and reliable, as usual!

Thanks for the tip, Els!

Offline

Board footer

Powered by FluxBB