Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Can article_custom be used inside an article body?
Hello,
In the last of my frequent visits to the Textpattern wonderful FAQs, my blood froze as I read the following:
QUESTION: Can I use Textpattern tags in article bodies?
ANSWER: Some, but not all. In particular, <txp:article /> and <txp:article_custom /> usually won’t work at all, and are likely to fail in subtle ways if they do.
I first saw the use of a article_custom inside an article body in the book Texpattern Solutions (in page 172) in an section about the use of keywords.
It went something like this:
This would be in the article body:
<ul class="relatedprojects">
<txp:article_custom section="projects" form="quick_projects_link" keywords="Rem Koolhaas" />
</ul>
This would be the form quick_projects_link:
<li>
<txp:if_custom_field name="content_in_body" val="yes">
<txp:permlink><txp:title /></txp:permlink>
<txp:else />
<txp:title />
</txp:if_custom_field>
</li>
Which would return something like this:
<ul class="relatedprojects">
<li>Lille Grand Palais</li>
<li><a href="url">Casa da Música</a></li>
<li><a href="url">Kunsthal</a></li>
<li>CCTV Headquarters</li>
(...)
</ul>
And up until now I was planning to use this profusely in a new project I’m working on.
I’m (kind of) hoping txp faqs are outdated!
Are there any alternatives to this kind of tagging? I’m trying to achieve a kind of tagging system without resorting the use of a plugin.
Thanks
Last edited by goncalo.dumas (2010-04-07 13:02:21)
Offline
Re: Can article_custom be used inside an article body?
The key to the FAQ is in the sentence:
In particular, <txp:article /> and <txp:article_custom /> usually won’t work at all
(emphasis mine). Usually doesn’t mean it won’t work, it just means you may get undesirable results if you embed an article or article_custom tag inside another. The reason is often because of the increased likelihood of a circular reference. You’ll notice in the example that the article_custom tag specifies a form — that’s important. Had it not done so it would have used the default form. If you were also using the default form for the ‘outer’ article tag, TXP would tie itself in a knot very quickly (luckily it detects this eventuality and gives you an error message).
Also, if you are inside an article tag’s container/form, it ‘loads up’ the info about the article so it’s available for you to use. For example, title, body, excerpt, custom field info, etc. If you then put another article tag inside your existing article tag, it may mess up this information or overwrite it with stuff from your ‘inner’ article tag (I think since TXP 4.0.8 it defends against this by keeping a note of the existing article, but it’s sometimes better not to do it if there’s any other way to achieve what you want).
So the rule is that there is no rule against it. But if you can possibly avoid it you’ll probably save yourself some potential headaches. There are probably other reasons to do it (or not) that other people can give you but I hope the above at least helps clear things up a bit.
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
Re: Can article_custom be used inside an article body?
@Gonçalo A little closer to the case defined by the quoted code (Bloke is a developer & English :):
<txp:article_custom />
always produces lists: article_custom will always return an article list and is not context-sensitive
Play around with it in article or page context and you will get section independant lists (“article_custom can see all posts from all sections, categories and authors”). In this case above article_custom is used as a simple hard coded search inside a section for articles having a certain keyword which is totally fine.
The code example works (which answers your question in a satisfying way I hope).
Edit:
Are there any alternatives to this kind of tagging? I’m trying to achieve a kind of tagging system without resorting the use of a plugin.
The plug-ins tru_tags [stable] or smd_tags [beta] (for tags, made by Bloke) are essential for a good tag system inside Textpattern.
Last edited by merz1 (2010-04-07 18:33:19)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
Re: Can article_custom be used inside an article body?
Thank you both!
In fact I’ve been looking at Stef’s smd_tags and it looks promising.
But due to the fact that I’m using heavy-weight MLP, I have this rule of thumb not to use another plugin unless it’s absolutely necessary.
But now that smd_tags was mentioned, I would love to know, in a nutshell ;-), if what I want is possible:
I’m rethinking the site of my employer (pro bono, unfortunately) and would like to make it more dynamic by linking information that it is currently displayed in a static fashion.
The two main information blocks are “entities” (which comprises both customers and partners) and “works”, we, the company, stay in the middle.
Every “work” occurrence is a post.
Every “work” occurrence refers is related entities (usually, one customer and one partner, but it can two customers and one partner or one customer and three partners…)
“Entities” are not posts. They should be categories, custom fields or tags.
Categories:
In a standard txp install, there are only two category fields from which to choose, and besides, they are already used for “works” categorisation.
Extending categories with plugins can (will, did) conflict with MLP.
Custom fields:
glz_custom_fields: Very easy to use but not sure if it fits the task (sincerely, I don’t remember why though)
Tags (Keywords):
So far, the best option, although only partially automated if I skip the use of a plugin…
I will take a closer look to smd_tags.
Stef, Is there any tutorial on smd_tags? It would be cool to have a practical example. I must admit I got a little scared when I saw the help page’s length ;-)
Offline
Re: Can article_custom be used inside an article body?
I must add that the use of keywords described in the first post don’t work like tru_tags or smd_tags.
Both these plugins return their results in a special section, while the combination of article_custom and keywords immediately render the links in situ using an unordered list.
These nested results can them be hidden using a javascript contraption.
Offline
Re: Can article_custom be used inside an article body?
goncalo.dumas wrote:
Extending categories with plugins can (will, did) conflict with MLP.
In theory (untested) with smd_tags you can create tags for each language — you could sub-categorize them under the language code or link them to category if you wish. For example:
en-us
--> tag-1
--> tag-2
se-se
--> tagen-1
--> tagen-2
or something like that. Not sure if you could limit the interface to only show/allow the tags for the current language. That’d be an interesting exercise.
Is there any tutorial on smd_tags? It would be cool to have a practical example. I must admit I got a little scared when I saw the help page’s length ;-)
That’s the standard modus-operandi for all smd_ plugins :-) The docs are way over the top but I’m getting better at organising them… s-l-o-w-l-y.
With regards examples, here’s how to implement related images. That’s just one way of using the ridiculously powerful <txp:smd_related_tags>
.
Both these plugins return their results in a special section, while the combination of article_custom and keywords immediately render the links in situ using an unordered list.
That’s only half true in the case of smd_tags (I can’t speak of tru_tags: never used it in anger).
If you were to set up your entities as tags and then assigned certain tags to your work articles, you could easily display the tags associated with that article in-situ using <txp:smd_tag_list>
. If you wished to display related articles by tag (or tag->category, tag->keyword, tag->custom_field, or pretty much any other combination of fields) you could add smd_related_tags inside your article or (I think) even inside yout tag list’s container.
Only if you allow people to click on one of the tags will it take you to a landing page where you can show related/other articles/files/images/links with the same tag(s) — singular or plural: I seem to remember that in smd_tags ‘OR’ searches are available from the URL… ‘AND’ matches are pending (or was it the other way round…? My memory’s not what it once was).
Also in smd_tags the destination URL is configurable so you could make it look like another section of your site, or even disguise the URL with gbp_permanent_links. There are plenty of ways to use the plugin, you just have to get your head round what it is you’re trying to achieve first and configure it accordingly!
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
Re: Can article_custom be used inside an article body?
Thanks Stef, you rock!
Offline
Re: Can article_custom be used inside an article body?
@Gonçalo You should try tru_tags first and check out if you hit borders. smd_tags, as you can read in the first post in the forum thread, is Blokes approach to widen the features which are possible with tags.
You might even use both plug-ins to get a mix of stable and beta :)
… I’m using heavy-weight MLP
I am not so I am no help with MLP + tags.
I must add that the use of keywords described in the first post don’t work like tru_tags or smd_tags.
Both these plugins return their results in a special section, while the combination of article_custom and keywords immediately render the links in situ using an unordered list.
Well, the reason for a ‘tag search result page’ is pretty easy: Which keyword to choose from n keywords to show related articles? What happens if you have 15 multi langual keywords for one article?
Clicking a tag link from a tag list with n tags will always trigger a database search. I am not sure though how heavy txp:smd_related_tags
is performance wise.
In general using keywords (as tags) inside a living & existing TXP site is very elegant:
- Maintenance
- Easy abstract
- not context-sensitive (like article_custom)
“Entities” are not posts. They should be categories, custom fields or tags.
Is an entity a synonym for a concrete project? If yes I would use a custom field ‘project’ and trigger a search for all posts which contain that value. Tags are not that easy when it comes to boolean logic.
If you need boolean AND/OR combinations you can use n custom fields (project: name, partner, year,…).
Thanks Stef, you rock!
Definitely YES, but using his plug-ins is addictive and can lead to deep & sustainable mind distortions :)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline