Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2009-12-07 22:28:29
- bottlerocket
- Member
- Registered: 2009-12-07
- Posts: 11
Newbie Q: Custom article display
Hello there,
I am pretty new to textpattern development and I think i may well have hit a wall due to being too ambitions early on in the learning curve.
I have done a reasonably complex blog layout which displays the last 6 posted articles. Each of these 6 articles is displayed in a custom way on the page, so doing a single <txp: article..> wouldn’t work as I need to display certain articles in certain ways. E.g. the latest article is massive on the page with a massive pic, the next two are smaller with a different size image, and the last 3, have no image at all.
Basically, its a much more editorially driven layout. Anyway, that’s the aim….
At the moment it exclusively uses <txp:article_custom..> to pull each of the last 5 articles individually by way of <…limit=“1”..>. This is then combined with the <…offset=“x”..> attribute to determine which article goes where.
Maybe my logic is a bit skewed and it does seem rather hacky. Like I said, my TXP dev experience is very limited.
Anyway, I hit a stumbling block when it comes to displaying the full article. the <txp:if_individual_article> doesnt seem to work or apply here. I cant seem to see it working without some massive conditions nested within conditions. The good thing is each article is displayed in exactly the same way, so to me, the most straight forward approach would be to link to an ‘article display page’.
However, I am having trouble making that link or working out how to do that
Can anyone shed any light onto what I shold be doing and what things I should be looking at?
Thanks in advance
Offline
Re: Newbie Q: Custom article display
bottlerocket wrote:
Each of these 6 articles is displayed in a custom way on the page, so doing a single <txp: article..> wouldn’t work
If the stumbling block is using the article tag, there may be a way to do it. One option is to use the adi_calc plugin to increment a variable’s value inside your article form/container. Thus each of your 6 articles gets assigned a unique value.
You can then test the value using txp:if_variable, smd_if or smd_multi_choice. For example: <txp:article form="editorial" />
and in form editorial
:
<txp:adi_calc name="anum" add="1" />
<txp:if_variable name="anum" value="1">
First article content/layout here
</txp:if_variable>
<txp:if_variable name="anum" value="2">
Second article content/layout here
</txp:if_variable>
...
Or you could simply use the variable’s value to change a container’s class, perhaps using smd_multi_choice:
<txp:adi_calc name="anum" add="1" />
<div class="<txp:smd_switch item="?anum">
<txp:smd_case value="1">level_1</txp:smd_case>
<txp:smd_case value="2" />
<txp:smd_case value="3">level_2</txp:smd_case>
<txp:smd_case value="4" />
<txp:smd_case value="5" />
<txp:smd_case value="6">level_3</txp:smd_case>
</txp:smd_switch>">
Article layout goes here
</div>
(you ought to be abe to use smd_multi_choice’s default
attribute for the last 3 cases but for some reason it’s not working so I think there’s a subtle bug in the plugin which I’ll have to try and track down)
Or with smd_if (might be slightly less efficient, but it looks neater):
<txp:adi_calc name="anum" add="1" />
<div class="<txp:smd_if field="txpvar:anum" operator="eq" value="1">level_1</txp:smd_if>
<txp:smd_if field="txpvar:anum" operator="in" value="2/3">level_2</txp:smd_if>
<txp:smd_if field="txpvar:anum" operator="gt" value="3">level_3</txp:smd_if>">
Article layout goes here
</div>
Hope the above isn’t way off base and is of some use. If not, we’ll have to wait for a proper tag guru to arrive and save the day!
Last edited by Bloke (2009-12-07 23:25:56)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#3 2009-12-07 23:26:41
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Newbie Q: Custom article display
bottlerocket wrote:
… link to an ‘article display page’.
However, I am having trouble making that link or working out how to do that
To link to an individual article you need the <txp:permlink> tag.
And to display the individual article you need a <txp:article />
tag on the page. If you are displaying those 6 latest articles on the section page (the same page as your individual article should be displayed), you can do something like this:
<txp:if_individual_article>
<txp:article form="your-single-article-form" />
<txp:else />
// here all your article_custom tags
</txp:if_individual_article>
If your setup is different, you’ll have to tell us what it is exactly ;)
Edit: late again ;) I’m curious now if I totally misunderstood the problem, because Stef’s reply is very different… ;)
Last edited by els (2009-12-07 23:28:45)
Offline
Re: Newbie Q: Custom article display
Hah…two very different answers. But I think their both important points…As long as you are on the permlink of the article (for example if using /section/article it might look like www.mydomain.com/mysection/this-is-my-article) then <txp:if_individual_article />
should apply (Right? Sudden self-doubt).
And, Stef’s approach to output articles using a single <txp:article />
list, and then use some incrementing method to customize the output for each one seem the clever way to go.
Offline
#5 2009-12-10 22:28:28
- bottlerocket
- Member
- Registered: 2009-12-07
- Posts: 11
Re: Newbie Q: Custom article display
Hi Guys,
Thanks for the help it was actually a lot simpler than I thought in the end thanks to Els post and code that clarified it for me. I essentially implemented as he suggested and its working well. I think I my thinking had got a bit twisted.
So once again, thanks for the input from all.
BTR
Offline
Pages: 1