Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Nesting articles: getting content of one article to show up in another
This is perhaps more of a “how to” than that it is a real question, however I had this problem and came up with the solution below. If anyone knows of a better way to do this, I would like to know!
My Problem:
I run a small publisher and am making a website for us. What I want to do is to easily have content of one article show up at another article. For example: I have made articles for individual books we have published, and I have made articles for our individual authors. What I would like is that at the authors’ article (containing a bio and picture), also a list is generated with all books written by that author. Ideally this would be generated automatically.
Likewise I have several other places in my site where I would like to include information from the book article (containing info on title, author, abstract, isbn etc) to show up for example at a press-release I post for that specific book.
How I solved it:
What I did is perhaps not considered a proper use of TXP but is does the trick. If anyone knows of a better way, please let me know.
In the case of the booklist being generated at the bottom of the authors’ article: I want to have a list of all books by that author. The authors name should thus be the key. I have entered the authors name in a custom field (named: “authorname”) in both the book article(s) (in section called bookinfo) and the author articles. Now at the bottom of the article form I use for displaying the authors’ page I put in the following code:
<txp:article_custom section=“bookinfo” authorname=’<txp:custom_field name=“authorname” />’ listform=“Book_by_author” pgonly=“0” searchall=“0” sort=“Posted desc” status=“4” />
What the above does, it basically matches articles with identical values in the custom field “authorname”. It calls in the value from the customfield “authorname” in the current article (being the author’s biography page) to look for articles in the section “bookinfo” for articles that have identical values in their custom fields by the same name.
If it finds a match, it calls in listform “Book_by_author” to display the results. This listform can be edited just as a regular listform to display the article picture, the title, the ISBN, a short abstract, what ever info you have included in the Bookinfo article.
The result is that at the bottom of my Authors’ page a list is generated of all books that are written by this author. Also when I add a new book with the authors name in the customfield “authorname” it is automatically added to display at the author’s page.
Calling in single unique values:
In the case of a press-release considering a particular book, I want for example to display basic information about the book such as the title, the name of the author, and perhaps a link to the books individual page. However, as I entered all this information already in the bookinfo article it seems double work to also enter it in the press release. Therefore I use the custom field named “ISBN” (being a unique code linked to a particular book) to call in the info needed. All I need to do in the press-release article is to fill in the ISBN of the book to which the press-release is related, and than I can do the following:
<txp:article_custom section=“bookinfo” isbn=’<txp:custom_field name=“isbn” />’ listform=“citation_title” searchall=“0” limit=“1” />
The above uses the ISBN I filled in in the press-release article to look up all articles in the section “bookinfo” with the same ISBN, which of course should reveal only 1 match as it is a unique key. Just to be safe I set the limit to “1”. The result is that it will display the list of results (n=1) using the listform=“citation_title” which consists merely of the following:
<txp:title />
As such the title from the corresponding book is depicted in the press-release. The cool thing is that all book information is loaded from one place. So when I find a type-o or need to change something, I only need to edit the bookinfo article to have the correct info show up everywhere it is “cited”. Likewise you can use the above technique to call in as many elements as you like, now I only called in the title, but you can of course make a whole list of all sorts of different elements you want to include form the bookinfo article. Also very handy is to use this to call in a <txp:permlink>, alllowing you to put in a link in any article to an article with an identical customfield-value, in this case ISBN.
I am very curious to learn if there are more efficient ways of doing what I am doing with the above, if not, the above might be helpful to others as I haven’t come across other solution to this “problem”.
Cheers!
Last edited by sidekarsten (2011-08-11 18:50:39)
Offline
Re: Nesting articles: getting content of one article to show up in another
Hi
I like the way you solved it but I see a problem with your code.
correct syntax should be
<txp:article_custom section="bookinfo" authorname='<txp:custom_field name="authorname" />' listform="Book_by_author" pgonly="0" searchall="0" sort="Posted desc" status="4" />
and
<txp:article_custom section="bookinfo" isbn='<txp:custom_field name="isbn" />' listform="citation_title" searchall="0" limit="1" />
note the single codes when using a tag in tag.
Last edited by colak (2011-08-11 07:43:25)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Nesting articles: getting content of one article to show up in another
Thanks, the “<txp:custom_field >” field was working, but if it is incorrect syntax, I will change it to ‘<txp:custom_field>’
Cheers!
Last edited by sidekarsten (2011-08-11 08:27:12)
Offline
Re: Nesting articles: getting content of one article to show up in another
Just found out something I didn’t know, you can use “%” as a wildcard. I had a problem with books that have multiple authors, as in those case I cannot make a direct link to a book and an author as the authors field will contain several names… however, in those cases you can do this:
<txp:article_custom section="bookinfo" authorname='%<txp:custom_field name="authorname" />%' listform="Book_by_author" pgonly="0" searchall="0" sort="Posted desc" status="4" />
By adding “%” it doesn’t merely link the two articles where “authorname” is identical, but it links to all articles (or books) in the section “bookinfo” that contains the name of the current author. So also if there is a second or third author to a specific book, as long as anywhere in the custom field “authorname” the name of the author is listed, this code will have the book show up in the list of books attributed to this author. Very cool indeed.
Offline
Re: Nesting articles: getting content of one article to show up in another
If you don’t want to use different forms for pulling in content, you can also use <article> as a container tag instead, helps you to keep things a bit more tidy and in one place!
example to pull in body text from another article based on a unique key (in this case ISBN):
<txp:article_custom section="abstract" isbn='<txp:custom_field name="isbn" />' searchall="0" limit="1">
<txp:body />
</txp:article>
Offline
#6 2011-12-27 17:50:03
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Nesting articles: getting content of one article to show up in another
sidekarsten wrote:
<txp:article_custom section="abstract" isbn='<txp:custom_field name="isbn" />' searchall="0" limit="1"> <txp:body /> </txp:article>
I know what you did can work in some cases, but still it’s better to use the correct closing tag: </txp:article_custom>
;)
Offline
Re: Nesting articles: getting content of one article to show up in another
Ah, yeah, of course, thanks for that Els!
Offline