Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-07-02 19:32:21

ploinkr
Member
From: Montreal
Registered: 2007-12-06
Posts: 83

related articles with custom field?

Hello there,

I’ve been trying to implement a short list of related articles in a sidebar next to certain articles but I’m a bit lost as to how to proceed.
This short list would appear under specific names, related to values in a custom field.
For example, the main article is about the artwork being presented in our gallery. The related articles are either texts or videos and would bear those very values in a custom field.
Also, ideally, the list item wouldn’t appear should there be no text or video related to the main article.
Here’s a screenshot of what it could look like

I would very, very much appreciate if anyone can help steering me in the right direction.
Thanks,
Ben

Offline

#2 2009-07-02 19:54:01

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: related articles with custom field?

I’ve done more or less exactly what you describe, using the sed_pcf_for_each_value tag in the sed_packed_custom_fields plugin to produce the list of related articles. Other tags in that plugin would allow even more control if you want to treat text articles and videos separately.

Edit: corrected link href

Last edited by jsoo (2009-07-02 20:07:19)


Code is topiary

Offline

#3 2009-07-02 20:05:14

ploinkr
Member
From: Montreal
Registered: 2007-12-06
Posts: 83

Re: related articles with custom field?

Thanks jsoo, will look into that. Do you know if it’s compatible with glz_custom_fields?

Offline

#4 2009-07-03 15:48:25

ploinkr
Member
From: Montreal
Registered: 2007-12-06
Posts: 83

Re: related articles with custom field?

jsoo, do you mind me asking if you can provide more details as to how you did it (with sample code, for example?)
Having a hard time grasping how to use that plugin in my context.
Thanks,
B.

Offline

#5 2009-07-03 17:08:45

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: related articles with custom field?

Benoit, there’s a thread with a very similar request: can some of the information in this thread help you? Plugin solutions are in #11 (replace “video_id” with custom_n, where n is the number of your cf) and #13.

Last edited by uli (2009-07-03 17:17:05)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2009-07-03 17:16:37

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: related articles with custom field?

It’s slightly more involved than I had thought; I forgot I am using a little trickery to get relevant link text.

I have a custom field named “Related”, containing a comma-separated list of article IDs. By using an if_custom_field block, articles with a value in that field call up a form (related_articles) containing this:

<h2>Related articles</h2>
<txp:sed_pcf_for_each_value name="related">
<a href="<txp:permlink id="{value}" />"><cite><txp:soo_title_from_id id="{value}" /></cite></a>
</txp:sed_pcf_for_each_value>

soo_title_from_id is a plugin I haven’t released publicly, because it’s such a single-purpose little thing. But here it is if you’d like to use it:

H4sIAAAAAAAAA+1VS2/jNhA+m79iqmTXdmHrFSdxKFnYBYIC6aGHbXsqCoMWKYuoJGpJKo5r 5L93KEu7mya99VT0IInz/maGM2I0iujJ0Oiaeqyq1GFb2rralqJqvUTSKDH0lnqPQhupGg+p K+qFfuRON2jR2VJpR6yp96MoCvhZKUdG4Sjcdlo6ThxRr7S2pUEgWyO4fJLWb4QNenUUcmFy LVs7xIkx7A/C5iUwbWVeCbDS4rvQqoaHe6eyop49tsLhDM9kw2rR+0Njo9S2N9k6k63kg8k5 NUzr7o56k7TNUmOPlcgItFrAqWWcy2ZPIfSvRQ2RqBPYsfyPvVZdwylcCCGQozQXmkLUPgFn phQcLvI8T54JlNECyhifK/dArjh6LVRjlwWrZXWkYFhjlkZoWSTQCw5C7ktL0WvFX7qAU830 XjbLShSosHRwnMJLoVUthXgQRUM0I/8UyPVXo8kLfuSvB/7V3/iDfiXhVEmDfFedpSs0BS5N PgjflOdSY6e+arypZD53TI9K7NsCjXVolK5Z5TR8LT53Ugu+AP/AdIOdgVOuKqUpMp1GGpzb lwZtRsgkLaPsVefTALlO2GafhO10Y8CW44VSRU+Mt8y0IpeFxIbujnjPfPhJWcTYWPGEaYjG SCsfhf8lXJx9tFbLXWeFwThxz+2qjEwmaSWz1KWXSb55f3G1SiS62Qvdn9OgF6U7DUFGUtOy BvKKGbPxxqQ9hHs+YZYoz3z4OMB8uIemq3dCIxIMgzEDF/SM6FfD9mIAk+Ktzt5f3ISJfWrp q9LACC2O+g8EqBsnBPNDu2FkHNB+JkOcK1J0Te6mFF45m10ya80cTogDy6VZbmcVlsfMmNbs OMOaTCWfTjbZZDpdkMl8AWeLeYIWsoAZfAeXCGqOmrrvlBNcatjg0BRiq9VhNv3FhZwuYOpa 0qK90I0jH+43MPWxxI+smqEX5/XsFB189YjUb4OP3xPyPCwvtxW2mh36xXaLaf6/Ff4LW4GQ MvJfX1RC/q09gAFinMovK4CQ7+EDzpQ3jLr3gbybjXDn4zi/e2uQz6762SUEb50P6T+OrBdH Hq6N4Ydc8+v+FOO/+WZ1HbM4Zqs4vgvXfLdiRXgTcSbC2zVbrb3k+S/7f6/y8wcAAA==

Now that I see uli’s response, that’s another tack you could take. However you would lose control over sort order.


Code is topiary

Offline

#7 2009-07-03 17:21:13

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: related articles with custom field?

Hmm, now I’m wondering if there isn’t a vastly simpler solution: feeding the contents of the custom field to the id attribute of an article_custom tag.

Edit: Again, losing control over sort order.

Last edited by jsoo (2009-07-03 17:22:01)


Code is topiary

Offline

#8 2009-07-03 17:31:42

ploinkr
Member
From: Montreal
Registered: 2007-12-06
Posts: 83

Re: related articles with custom field?

Uli, jsoo, thanks a lot for the suggestions and links – and jsoo, very kind of you to share you plugin!!
Will dabble in that today and let you know about the results.

Thanks again for your help!
Ben

Offline

#9 2009-07-03 17:35:48

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: related articles with custom field?

OK, this works, again losing any arbitrary sort order implied by the custom field contents (the more elaborate method using sed_packed_custom_fields preserves this order), but it sure is simpler:

<txp:if_custom_field name="related">
<txp:article_custom id='<txp:custom_field name="related" />' break="li" wraptag="ul">
<cite><txp:permlink><txp:title /></txp:permlink></cite>
</txp:article_custom>
</txp:if_custom_field>

Assumes article context.


Code is topiary

Offline

#10 2009-07-03 17:59:56

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: related articles with custom field?

edit: while writing my reply, jsoo already posted some similar solutions.

Last days I’ve been thinking deeply (beware!) about how to relate a bunch of articles, so to be able not just to output a main article and then some links to or chunks of other related articles but also to generate some cross-reference.

It all began after a meeting with a potential client who needs a site for listing books, but also to list book authors (and books by that author) and publishing houses (and their related books).

For sure, this can be easily done by just using custom fields with numerical values, and then using the magic of txp tags in txp tags. That alone should be enough for “glueing” articles in many different ways.

For example, if it’s a book, it will have two custom fields: author and publishing_house. Both the author and the publishing house are also articles in TXP. So they have been created before the book. Then, on both custom fields, you simple write the article id of the corresponding author/publishing house article.

This is enough, I think, for start fetching related articles to the current article (being it a book, an author or a publishing house).

For example:

List books by a publishing house (on the publishing house permalink).

<txp:article>
<h2>Editorial Planeta</h2> <!-- publishing house name -->
... some text...
</txp:article>
<h3>Books published by this publishing house</h3>
<txp:article_custom section="books" publishing_house='<txp:article_id  />'>
<txp:title /> <!-- book title -->
... more txp article tags...
</txp:article>

List books by author (on the author permalink).

<txp:article>
<h2>Jorge Luis Borges</h2> <!-- publishing house name -->
... some text...
</txp:article>
<h3>Books published by Jorge Luis Borges</h3>
<txp:article_custom section="books" author='<txp:article_id  />'>
<txp:title /> <!-- book title -->
... more txp article tags...
</txp:article>

Both examples above are just quick’n‘dirty approaches that probably can be refined.

So, with just built-in TXP tags and the power of tags in tags, it seems to be possible to relate articles.
Of course… typing a number on a custom field is a task prone to errors for our clients…

So, I’ve also been thinking how could this be addressed by TXP, probably using some plugins…

Some plugins that might be helpful to create an streamlined “workflow” for relating articles…

  • jsoo_multidoc: I’ve yet to ask J Soo if his multidoc plugin is supposed to be used for relating articles that aren’t necessary multidoc articles.
  • glz_custom_fields: convert a custom field to a dropdown menu (a select) and prepopulate the options with the titles of articles. For example, on the custom field author, create a dropdown with all TXP articles from section Author. On publishing_house, a dropdown with all publishing house names.
  • wet_peex + wet_quicklink: similar to above, when clicking on a custom field input, open up the wet_quicklink modal and display all articles from the corresponding section. Click on an article, and its id is added to the custom field input field. In other words, a mechanism similar to jmd_img_selector or upm_file_popper or any other plugin that populates a custom field with an id.
  • wet_peex alone: similar to the glz_custom field solution. Fetch the articles using wet_peex and then do some clever jQuery magic to create dropdowns on the fly, and replace those boring input field (for custom fields). Select the related article, and then, the corresponding option/value (again, the related article id) is populated in the (hidden) custom field input field.

Well, sorry for my rough english, this all came off the top of my head.

Last edited by maniqui (2009-07-03 18:08:47)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#11 2009-07-03 19:03:15

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: related articles with custom field?

maniqui wrote:

jsoo_multidoc: I’ve yet to ask J Soo if his multidoc plugin is supposed to be used for relating articles that aren’t necessary multidoc articles.

Wouldn’t be a good fit for this; Multidoc only allows an article to belong to one Multidoc collection (i.e., multi-part article).


Code is topiary

Offline

#12 2009-07-04 12:25:31

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: related articles with custom field?

With apologies to artagesw, who posted a cogent warning here, because this is going off the high dive into the deep end of MySQL-specificity ;)

Extending my native-tag solution with a method for preserving the order of article IDs in the custom field:

<txp:if_custom_field name="related">
<txp:article_custom id='<txp:custom_field name="related" />' sort='field(<txp:custom_field name="related" />)' break="li" wraptag="ul">
<cite><txp:permlink><txp:title /></txp:permlink></cite>
</txp:article_custom>
</txp:if_custom_field>

Note the sort attribute in the article_custom tag. Note also that as written this only works with a list of numbers in the custom field, which don’t need to be quoted for the query. You’d have to throw in some raw PHP to do the same kind of thing with a list of names.

Edit, 2009/07/17: Oops — missing the column name: sort value should be

sort='field(`ID`, <txp:custom_field name="related" />)'

Not tested, but that ought to work.

Last edited by jsoo (2009-07-17 16:53:15)


Code is topiary

Offline

Board footer

Powered by FluxBB