Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Form displaying excerpt AND full article
I used the sample code found in the <a href=“http://textpattern.com/faq/24/how-do-i-show-only-an-excerpt-in-article-lists”>faq at this page</a> to create a form that displays an excerpt if there is one, or just the full article if there isn’t an excerpt. However, the form is displaying both the excerpt and the article. The first line is how I call the form in the page template and the rest of the code is from the form itself. (I would have separated each with code blocks, but I couldn’t figure out how to close off a block of code with the “bc..” marker.) What is wrong with my code? Thanks!:
bc..<txp:article listform=“news_article” limit=“5” />
<txp:if_article_list>
<!— display the short version —>
<h3><txp:permlink><txp:title /></txp:permlink> · <txp:posted /></h3>
<txp:excerpt /> <txp:permlink>read more >></txp:permlink>
<br /><br />
<txp:else />
<!— display the complete article —>
<h3><txp:permlink><txp:title /></txp:permlink> · <txp:posted /></h3>
<txp:body />
<br /><br />
</txp:if_article_list>
Offline
Re: Form displaying excerpt AND full article
You’ll need to use the piece of code from the bottom of the FAQ, where it says “Conditional Layout”. This code will display the excerpt if there is one and then print the body:
<pre>
<txp:if_excerpt>
<div class=“excerpt”><txp:excerpt /></div>
</txp:if_excerpt />
<div class=“body”><txp:body /></div>
</pre>
You might want to put this on your form where the <!-- display the short version -->
section is, instead of the part that prints out the excerpt and the “more” permalink.
[Lee]
Monkeys could have written a better post..
Offline
Re: Form displaying excerpt AND full article
Thanks Lee.
I may not have been clear, but I want either the excerpt or the full text displayed, not both. When I read that code, I see that it is going to display the full text and an excerpt, if there is one. So that doesn’t do what I want it to. Am I reading that wrong?
Offline
Re: Form displaying excerpt AND full article
You’re right, this will display an excerpt if there is one. If you want one or the other, use this:
<pre>
<txp:if_excerpt>
<div class=“excerpt”><txp:excerpt /></div>
<txp:else />
<div class=“body”><txp:body /></div>
</txp:if_excerpt />
</pre>
[Lee]
Monkeys could have written a better post..
Offline
Re: Form displaying excerpt AND full article
Lee – I was just coming back to apologize ‘cause you pointed me in the right direction. This is what I had to do to get it working. So, thanks! (And hey, can you tell me how to close off a block of code here in the forums? I just saw you did it in the post above…):
bc..<txp:if_article_list>
<txp:if_excerpt>
<!— display the short version —>
<h3><txp:permlink><txp:title /></txp:permlink> · <txp:posted /></h3>
<txp:excerpt /> <txp:permlink>read more >></txp:permlink>
<br /><br />
<txp:else />
<!— display the complete article —>
<h3><txp:permlink><txp:title /></txp:permlink> · <txp:posted /></h3>
<txp:body />
<br /><br />
</txp:if_excerpt>
</txp:if_article_list>
Offline
Re: Form displaying excerpt AND full article
ywickham wrote:
So, thanks!
No problem, sorry it took two tries ;)
(And hey, can you tell me how to close off a block of code here in the forums? I just saw you did it in the post above…):
I think the official way to display HTML is to wrap it with the code tag. I never got that to work properly, so I wrap HTML with a pre tag and convert all less than-symbols into &lt;. You can click the “quote” link below the earlier post and see the raw format of what I wrote.
There are probably better ways, but this works most of the time and I don’t have time to fool around with textile nuances.
[Lee]
Monkeys could have written a better post..
Offline
Re: Form displaying excerpt AND full article
Just a thought here Yazmin as I missed the bad closing last time but you are repeating your “h3” tag which as far as I can see is identical. You could just place it between the “if_list” and “if_excert” tags at the top and remove the other 2 instances. Then you would get the h3 followed by either the excerpt or the full body. Reduces the code a bit. :)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Form displaying excerpt AND full article
You are absolutely right. Thanks for the catch on the extra code!
Offline