Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-02-28 10:49:57

bmwg
Member
Registered: 2010-04-06
Posts: 39

switch between excerpt and article

I have a page template to display different products. Each product has it’s own category. There’s one sticky article per category which is the product text. And then there’s different live articles for each variation of the product. (soft-drink would be a category with it’s sticky article and several live articles for coke, sprite, ..)
This is my display form:

<txp:if_individual_article>
 <txp:article form="prodFormat" limit="1"/>
<txp:else />
 <txp:article status="sticky" form="prodFormat" limit="1"/>
</txp:if_individual_article>

This is prodFormat:

<h1><txp:title /></h1>
<div class="articleText">
<txp:body />
</div>

Works fine. But now I want to display the excerpt and add a ‘more’ link to allow the user to switch between the short description (excerpt) and the long one (body).
I changed the prodFormat to:

<h1><txp:title /></h1>
<div class="articleText">
<txp:if_excerpt>
<txp:excerpt />
<txp:permlink>more</txp:permlink>
<txp:else />
<txp:body />
</txp:if_excerpt>
</div>

Now I get the excerpt and the link, but the link doesn’t display the body. With the live articles, nothing happens. And with the sticky article I get a link to /section/category/article-title and nothing gets displayed. (My site structure is /section/category/ to display the sticky article of that category and /section/category/article-title to display the live articles)

How do I get the more-link right? And how do I get a less-link to switch back to the short text?

Offline

#2 2011-02-28 11:47:43

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: switch between excerpt and article

Not sure if I understand: do you want both live and sticky articles to display the more link? I understand that for live articles/products, but usually sticky articles are only used in article listing pages, above the live articles listing. So sticky articles usually don’t get an individual page. And you may need two different article calls in your page template. From wiki:

<txp:if_article_list>
   <!-- display the sticky article -->
   <txp:article form="myshortform" status="sticky" />
</txp:if_article_list>
<!-- now the regular article list --> 
<txp:article limit=5 />

So maybe you may also want to use different forms for sticky and live articles. If not, please explain.

About live articles, your form does nothing because the if_excerpt conditional is executed inside the individual article routine and always return ‘true’, so the excerpt is always shown, instead of the body. The logic is wrong: to have the option ‘excerpt OR body’ in individual articles page you have 2 ways:

  1. Use javascript: body (in a div) is first hidden, then shown on click the more link.
  2. Use a different url: section/category/article-title to display excerpt, and then add a variable to the url (and to the ‘more’ link) to show the body. Something like section/category/article-title?show_body=1. In article form you need a different conditional, with adi_gps plugin. In that thread you should see some useful code examples to replace the if_excerpt part.

Offline

#3 2011-02-28 13:17:37

bmwg
Member
Registered: 2010-04-06
Posts: 39

Re: switch between excerpt and article

Thanks for the reply. I went with your second hint and changed my article format to:

<txp:adi_gps />
<h1><txp:title /></h1>
<div class="articleText">
<txp:if_variable name="long_version" value="1">
 <txp:body />
 <a href="<txp:permlink />?long_version=0" title="<txp:title />">less</a>
<txp:else />
 <txp:excerpt />
 <a href="<txp:permlink />?long_version=1" title="<txp:title />">more</a>
</txp:if_variable>
</div>

This is the form to use with live articles. Now I want a version for the sticky articles without the article-title in the link. So I need to create a link with the form section/category/?long_version=1
It already works when I type in the link in this format in the address bar. I just don’t know how to create the link. Tried replacing txp:permlink with txp:category but this gives me section/category/category/?long_version=1

Offline

#4 2011-02-28 14:40:50

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: switch between excerpt and article

Yes, txp:permlink isn’t the way to go in that case. Try this:

<a href="<txp:site_url/><txp:section/>/<txp:category/>/?long_version=1" title="<txp:title/>">more</a>

(Not sure about the slashes between tags, try putting or removing them)

Offline

#5 2011-02-28 16:49:51

bmwg
Member
Registered: 2010-04-06
Posts: 39

Re: switch between excerpt and article

thanks a lot. even the slashes are right ;)

Offline

Board footer

Powered by FluxBB