How to use Excerpts ­ Coding ­ the bombsite

. . . .

Subscribe

Statistics

Article Comments
Categories
  • There are no categories in the Coding section
Famous Articles

Sign Up for Email Updates

Want to Send Me Something?

Need Some Icons?

How to use Excerpts

A question asked by many new to TXP is how can I have excerpts on the front-page with a read more link to the full article? It can be a little confusing trying to work this out as it relies on conditionals and nested tags. For a conditional to work you have to find some aspect which is different for the front-page and the single article page and that difference in this case is that the front-page is always an “article_list” even if you only show one article as I do here, it is simply a list of one, whereas the single article page is an “individual_article”. Remember that. I shall return to it in another article soon. Anyway armed with that information we can set about solving our problem.

In plain English we want to say that if we are viewing an article_list, and if there is an excerpt, show the excerpt, and if there isn’t one show the full body however, if we are in individual_article view, show the full body always.

TXP uses the default FORM template to show articles so this is what you need to edit. You can create your own if you wish but you will need to add the attribute “form=FormName” to your article tag on your PAGE template to make TXP use it. You must also ensure that you save your form as an “article” type so that it is grouped with all other “article” type forms in the sidebar on the “Form” tab.

In TXP tag form our English translates to:-

<txp:if_article_list>
<txp:if_excerpt>
<txp:excerpt />
<txp:permlink>But there's more</txp:permlink> (optional)
<txp:else />
<txp:body />
</txp:if_excerpt>
<txp:else />
<txp:body />
</txp:if_article_list>

Nested tags can be confusing and will not work if nested incorrectly. Note how there are two <txp:else /> tags in there. The first one is inside the <txp:if_excerpt></txp:if_excerpt> conditional tags so if there is an excerpt show the excerpt and the optional More… tag “else“ show the body.

The second <txp:else /> tag comes after the closing </txp:if_excerpt> tag so it now relates to the <txp:if_article_list></txp:if_article_list> conditional so we have “if_article_list“ do the excerpt conditional block “else“ just show the body.

Once you get used to it you should find it easy to nest tags in this way for all kinds of stuff because, if nothing else, it is completely logical.

Comments ( 6 )

  • 1
    Hamst3r Apr 12, 09:30 PM

    Thanks for this tutorial. I can’t get it to work though… :P

    Could you post or email me your whole default form so I can see exactly how it’s fitting in there?

    Thanks!

  • 2
    kakajoe Jun 19, 01:51 PM

    i wish there’s a step by step tutorial for this…cause i can’t use it on my web.. please ??
    thank u

  • 3
    Stuart (Author Comment) Jun 19, 03:46 PM

    That is a step-by-step but don’t forget that you need to create an excerpt for the article in the small bottom textarea on the “Write” page so that TXP can pick it up.

  • 4
    Coopo Jul 2, 07:14 AM

    Stuart
    Feeling a little dumb here because that excerpt box beneath the body box on the write page has gone missing.
    Hunh?
    No wonder I can’t formulate excerpts.
    Any ideas as to how to retrieve it?

  • 5
    Coopo Jul 16, 08:01 AM

    Yeah, worked out that missing excerpt panel question, finally.

    There’s a little button in the Admin/advanced/publish section that might be switched off automatically when you install rss_auto_excerpt.

    Or else some goose may have flicked it by mistake.

  • 6
    Stuart (Author Comment) Jul 16, 04:55 PM

    Aha! Well spotted.

Leave a Comment
  
 
BACK TO THE TOP
Need A Textpattern Expert?
Do you have an existing theme that you really like but it is designed for some other application?
Maybe you are a designer but lack the coding skills to turn your design into a working web site?
Maybe you are completely new to the world of web sites?

Then what you need is ME!

Get in touch for a quote