Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-07 06:24:28

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Can I put <txp:article /> or <txp:article_custom> in an article?

I know that <txp:article /> and txp:article_custom> tags normally go in page templates. But for my purposes, I’d like to plunk them down in articles.

I did one that way and it seems to work fine, but I wonder if there is any reason why I should not be doing this. Maybe the code wouldn’t be valid? A validator program looking at the page I generated gives some warnings, but I can’t tell if that’s related to my use of the <txp:article /> tag or not.

In case it matters to anyone’s answer, this is why I want to do it:

I’m going to use keywords with each of my articles and then use <txp:article keyword="whatever" /> tags to find all articles with a specific keyword.

Of course, I could put those <txp:article /> tags in page templates, but I want the user to see a different page for each list of articles with a specific keyword. So then, especially since I want URLs that include reference to the relevant keywords, I’d have to create a ton of sections (one for each keyword), plus either a bunch of different page templates or lots and lots of “if section” conditional tags in one template. It seems easier just to use a different article for each keyword.

I can’t use categories because I need to assign more than two “groupings” to many of the articles.

Also, I know that there is now at least one plugin that finds all articles that have been “tagged” with a given phrase. Something like that might seem like a good option for me, but I’m using a non-standard sortby attribute, so I think they won’t work.

Last edited by marknumberm (2006-01-07 06:25:21)

Offline

#2 2006-01-07 08:03:12

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

Sencer disapproves txp:article in txp:article.

Offline

#3 2006-01-07 08:22:23

takshaka
Archived Plugin Author
From: Below the Manson-Nixon line
Registered: 2004-06-02
Posts: 97
Website

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

I did one that way and it seems to work fine, but I wonder if there is any reason why I should not be doing this.

You probably got lucky. Article list tags don’t work properly when included in article content.

I’m going to use keywords with each of my articles and then use <txp:article keyword="whatever" /> tags to find all articles with a specific keyword.

You can use the chh_related_articles plugin to list articles related by keyword. You can even use a custom field to determine which keywords an article “links” to. But put the tag in your page or article form, not the article content.

Offline

#4 2006-01-07 08:29:32

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

Interesting.

This is what Sencer wrote:

<i>IIRC you can’t use article or article_custom tags in articles either (leaving aside the potential problem of infinit loops if it was possible).</i>

But the fact is that an article_custom tag is working in an article on my txp test site right now. (So, respectfully, I guess he didn’t recall correctly)

You could accidentally set up an infinite loop, I suppose, if you didn’t use attributes in your article or article_custom tag that excluded the article in which that tag itself resided.

If you avoid that, though, it does seem to work. So I guess my question is not whether it functions at all (it certainly seems to do so), but whether there is some other problem with it that I (being a relative newbie) have not thought of.

Last edited by marknumberm (2006-01-07 08:30:46)

Offline

#5 2006-01-07 08:57:37

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

takshaka, I was writing my reply to wet (#4) when your reply was published.

I had looked at the chh_related_articles plug in, but I couldn’t think of a way to make it produce a page with a list of articles sharing a common keyword that would also have that keyword appear in the URL.

But now I’m realizing I could just create an article that said something like “these are all the articles with the keyword ‘dog,’” give that article itself the keyword dog, use a title for the article that was “Articles About Dogs” (so the URL makes sense) and assign it to a section set up to use a page template containing the <txp:chh_related_articles relation="keywords" /> tag.

I would probably also make that article sticky.

And I could even use a <txp:article /> tag in a sidebar to list all the pages that are themselves lists of articles containing particular keywords. (If that makes any sense…it’s late where I live. Must sleep now…)

Offline

#6 2006-01-07 09:12:08

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

Oh, yeah: One other thing that gives me pause about this plugin is the note at the bottom of the example page:

<i>This plugin uses the same technique for matching keywords (and custom fields) as txp:article_custom: a simple substring match. This means that a search for the keyword “key” will return an article with a keywords field like “monkey,lemur,ape”, even though that’s probably not what you wanted. And if you list articles related by keywords to an article with keywords “monkey,lemur,ape”, you will get articles with keywords “duct tape” and “Cape Horn”.</i>

Doesn’t that mean that it wouldn’t really work at all if you had several keywords assigned to each article, as I plan to do?

Does it also mean that my original plan to use <txp:article keyword="whatever" /> tags wouldn’t have worked either — or at least not any better?

Offline

#7 2006-01-07 09:24:23

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

But the fact is that an article_custom tag is working in an article on my txp test site right now. (So, respectfully, I guess he didn’t recall correctly)

As takshaka wrote, you got lucky. A call to article(_custom) changes certain global variables which all article-tags need to function. It’s possible that the exact way you are using it, works for you, and of course nobody minds you continuing to use it. :)
But be aware that it might break anytime, and that you are using an unsopported, accidental “feaure”.

So I guess my question is not whether it functions at all (it certainly seems to do so), but whether there is some other problem with it that I (being a relative newbie) have not thought of.

You are entering uncharted territory, you tell us. ;)

Offline

#8 2006-01-07 15:43:21

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

You are entering uncharted territory, you tell us. ;)

Um, I think I’ll bow to the collective wisdom of the community and find a more secure way to do it. I don’t need the site to suddenly stop functioning on me.

The chh_related_articles plugin could work, but I guess I’d just have to be careful about setting up my keywords so that I don’t get unexpected results — e.g., getting articles w/ keyword “code” when I’m looking for ones w/ keyword “cod.” Are there any general tips about avoiding this?

Offline

#9 2006-01-07 17:52:52

takshaka
Archived Plugin Author
From: Below the Manson-Nixon line
Registered: 2004-06-02
Posts: 97
Website

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

I had looked at the chh_related_articles plug in, but I couldn’t think of a way to make it produce a page with a list of articles sharing a common keyword that would also have that keyword appear in the URL.

Oh, maybe I misunderstood what you wanted. Are you looking for something more like Ran Aroussi’s tags plugin? Or some combination of the two? I don’t really have a clear picture.

FWIW, I needed something similar to ran_txp_tags that I could use with several custom fields (or Keywords) per installation, so I’ll be releasing that plugin this weekend.

e.g., getting articles w/ keyword “code” when I’m looking for ones w/ keyword “cod.” Are there any general tips about avoiding this?

Eat less fish?

You could cheat and use some sort of extra delimiter characters: "'whitefish','cod'" and "'code','plugins'". Then keywords="'cod'" will only match what you want. But that’s pretty ugly.

I’m thinking about adding support for mysql’s find_in_set(), which would eliminate this particular problem.

Offline

#10 2006-01-07 19:17:42

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

Ran Aroussi’s tags plugin would be perfect except it cannot, from what I gather, accept attributes like “sortby=custom_1.” You’re stuck with an article list sorted by posted date, and that won’t work for me.

If by chance you could work that functionality into the plugin you’re working on, I would be your all time best friend. :)

What I ultimately need is a way to get individual pages showing all articles in a particular category — or containing the same keyword, or “tagged” with the same word (whatever). The articles need to be limited to one section and have “sortby=custum_1, custom_2, custum_3.” And I’d like to have each of those pages have a unique, human-readable URL.

The built-in categories function won’t work because (as many txp’ers have lamented in the past) you can’t have more than two categories assigned to any given article — and I’ll probably need more than that.

BTW, I also thought of the extra delimiter characters idea but don’t like it because, as you suggest, it’s not exactly elegant.

Offline

#11 2006-01-08 02:46:07

takshaka
Archived Plugin Author
From: Below the Manson-Nixon line
Registered: 2004-06-02
Posts: 97
Website

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

If by chance you could work that functionality into the plugin you’re working on, I would be your all time best friend. :)

I think the forthcoming chh_keywords does what you want right out of the box.

You can see a test case on this page. Studio and Genre are pulled from custom fields and link to the corresponding article lists.

BTW, I also thought of the extra delimiter characters idea but don’t like it because, as you suggest, it’s not exactly elegant.

Aye. As it so happens, mysql does a good job of matching keywords with find_in_set(), so that problem seems to be solved.

Hopefully, I’ll have a compiled plugin available tomorrow night.

Offline

#12 2006-01-08 02:54:15

marknumberm
Member
From: Minneapolis
Registered: 2005-11-29
Posts: 46

Re: Can I put <txp:article /> or <txp:article_custom> in an article?

You rule!

I looked at your sample page (which is very cool, btw), and it seems to be doing exactly what I need. I’m very excited to plug in the plugin.

Offline

Board footer

Powered by FluxBB