Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-12-26 14:09:00

sidekarsten
Member
From: Netherlands
Registered: 2011-08-11
Posts: 34
Website

Pulling content from one article into another article

I’m looking for a better way to get content from one article, to show up in another article, posted in another section.

I have for example a section called books with articles containing info on specific books, each article contains info on a specific books, with custom fields such as price, subject, title, author and isbn…

Now I also have for example press releases, different articles in a different section, but about some of the published books… so I would like to pull in book info about the book the press release is about from the book article posted in the section called books.

I now have a somewhat complicated way of doing this, using the ISBN as a key to pull in content, see my explanation here: http://forum.textpattern.com/viewtopic.php?id=36651

However, I was currently wondering whether I could also use something like <variable /> (http://textpattern.net/wiki/index.php?title=variable)

In theory I could do something like this in the article about the book using a custom field called isbn as key and price as the value for the book price:

<txp:variable name="<txp:custom_field name="isbn" />-price" value="<txp:custom_field name="<txp:custom_field name="price" />" />

and then, in the press release pull in the price of the book in the press release by using:

<txp:variable name="<txp:custom_field name="isbn" />-price" />

Now I would only have to fill in the ISBN of the book in the press release is about, and use this to potentially pull in all sorts of information from the book article.

However, this doesn’t seem to work… as apparently the <variable> cannot be used to pull in content from one article to another?

Suggestions anyone, can this not be done, or am I doing something wrong?

Cheers

Karsten

Last edited by sidekarsten (2011-12-26 14:10:50)

Offline

#2 2011-12-26 14:39:39

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: Pulling content from one article into another article

Karsten,

At glance you shoudn’t be using variable here. You just need <txp:custom_field name=“isbn” /> to pull the content of another article.
Assuming you have a custom field called linked_article_id or whatever suits your needs, you will then use it to call your other article by the ID attribute.
Such as:
<txp:article_custom id=’<txp:custom_field name=“linked_article_id”>’ ><txp:body /></txp:article_custom>

Not sure if this works, just from the top of my hat.

Edit: The above is in case you want to call another article from within the write tab, glue two articles together.

Last edited by hablablow (2011-12-26 16:00:39)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#3 2011-12-26 15:21:28

AndrijaM
Member
From: Belgrade, Serbia
Registered: 2007-12-22
Posts: 190
Website

Re: Pulling content from one article into another article

From inside article body you just write <txp:article_custom id=“xx” section=“section-name” /> and you can easy call content from another article

Offline

#4 2011-12-27 10:31:38

sidekarsten
Member
From: Netherlands
Registered: 2011-08-11
Posts: 34
Website

Re: Pulling content from one article into another article

Hey, not sure if that realy works as I want to, the linked article, is a way of manually linking two distinct articles… but that’s not what I want to do… in my site I use the book article as a main record to contain information about a book… and in several places in the website information about books is loaded from this central article with book information. Thus in the press releases the ISBN is used to pull in all required info about the book with the same ISBN, but at the author’s profile page, a list of all books written by that author is generated (the author’s name being the key) automatically in the same manner, and on the page with ebooks information about the book is also loaded in the same manner…

so, we are not dealing with two articles linked… but rather articles whose content is dynamically linked based on content (same authors name, same ISBN) depending on what information is required. How I do this is described in the forum thread linked to in the above post.

Although it works fine, the downside is that I need to make a article form for each variable I want to pull in to another article, which is a bit sloppy, I had hoped something like <variable> could de the trick more elegantly, but alas…

Thank’s for the feedback though

Offline

#5 2011-12-27 11:16:07

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: Pulling content from one article into another article

If all your information about a book is stored in custom fields except the author’s name, you have to cases:

<txp:article_custom author='<txp:author />' form="related-books-listing"/>
<txp:article_custom isbn='<txp:custom field name="isbn"/>' form="related-books-listing"/>

Except for the author’s case, If all the maching criterias are stored in custom fields, you can build a dinamyc textpattern tag, somethink like the next example, with the help of smd_macro plugin:

<txp:related_books criteria="isbn"/>

where “criteria” is the custom_field name you want to match (“isbn” for instance). This way your new tag will execute something like this:

<txp:article_custom {mycustomfield}='<txp:custom field name="{mycustomfield}"/>' form="related-books-listing"/>

Then you can retrieve books by any custom field:

<txp:related_books criteria="isbn"/>
<txp:related_books criteria="price"/>
<txp:related_books criteria="year"/>

And, If you want to complicate it more (but keep your code smart) with smd_macro, you can do something like this with your new smd_macro tag:

if criteria value=”“ (empty) then —><txp:article_custom author=…
else
<txp:article_custom {mycustomfield}=…

If no criteria, you are asking for match article author, else, you are asking for matching a custom field.

, covering the two cases, author and custom fields, with your new <txp:related_books/> tag.
….

Last edited by milosevic (2011-12-27 21:06:54)


<txp:rocks/>

Offline

#6 2011-12-28 10:48:57

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: Pulling content from one article into another article

Karsten

This is how I do it: I don’t think it solves your elegance concern. :-)

I don’t have a merged author field, I use custom fields Author_1, Author_2 etc

I also grab news articles (press releases included), Author Biography articles, Awards Articles, etc and assemble them into different sections.

My code could be laughable but it works.
I would love to compare code further since it is obvious we are covering the same ground.

best regards
Les Smith

<!-- Grabs Awards about the Author's Books -->
<txp:article_custom section='Books' Author_1='<txp:custom_field name="Author_1" />'  limit='10'>
<txp:if_custom_field name="awards">
<p class="minor"><strong>BOOK AWARDS</strong></p>
<txp:permlink><txp:title  /></txp:permlink>
<txp:upm_textile><txp:custom_field name="awards"/></txp:upm_textile>
</txp:if_custom_field>
</txp:article_custom>
<!-- Grabs Quotes about the Author's book -->
<txp:article_custom section='Books' sort="custom_4 desc" Author_1='<txp:custom_field name="Author_1" />' >
<txp:if_custom_field name="quotes">
<span class="quotemark"> ”</span>
<p class="minor"><strong>QUOTES OF NOTE</strong></p>
<txp:permlink><txp:title  /></txp:permlink>
<txp:upm_textile><txp:custom_field name="quotes"/></txp:upm_textile>
</txp:if_custom_field>
</txp:article_custom>
<!-- Grabs News about the Author -->
<txp:variable name="the_author"><txp:custom_field name="author_1" /></txp:variable>
<txp:article_custom wraptag="dl" section="News" limit="500" >
<txp:smd_if field="body" operator="contains"   value='<txp:variable name="the_author" />' >
      <p><txp:posted format="%B %Y" /> : <txp:permlink><txp:title/></txp:permlink></p>
</txp:smd_if>
</txp:article_custom>
<!-- Grabs News about the Author's Books -->
<txp:if_individual_article>
<txp:variable name="the_title"><txp:php>echo $thisarticle['title'];</txp:php></txp:variable>
<txp:article_custom wraptag="dl" section="News" limit="500" >
<txp:smd_if field="body" operator="contains" value='<txp:variable name="the_title" />' >
      <p><txp:posted format="%B %Y" /> : <txp:permlink><txp:title/></txp:permlink></p>
</txp:smd_if>
   </txp:article_custom>
</txp:if_individual_article>
<!-- Finds events that Author is appearing -->				
<txp:if_individual_article>
<txp:variable name="the_author"><txp:custom_field name="author_1" /></txp:variable>
<txp:article_custom wraptag="dl" section="Events" time="future" limit="100">
<txp:smd_if field="event_authors" operator="contains"   value='<txp:variable name="the_author" />' >
     <txp:if_different>
           <dt><txp:posted format="%B %Y" /></dt>
     </txp:if_different>
         <dt><txp:posted /></dt>
        <dd>
           <txp:permlink><txp:title/></txp:permlink>
       </dd>
</txp:smd_if>
   </txp:article_custom>
</txp:if_individual_article>
<!-- Grabs Contributors bio excerpts -->
<txp:if_individual_article>
<p class="minor"><strong>About the Contributors</strong></p>
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Author_1" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Author_2" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Author_3" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Editor_1" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Editor_2" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Translator_1" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Translator_2" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Illustrator" />'  limit='1' />
<txp:article_custom section='Authors' form='author_bio_excerpt' Author_1='<txp:custom_field name="Photographer" />'  limit='1' />

Offline

#7 2011-12-28 12:04:24

sidekarsten
Member
From: Netherlands
Registered: 2011-08-11
Posts: 34
Website

Re: Pulling content from one article into another article

Dear Les, yeah, this is exactly how I solved it too… seen my thread at http://forum.textpattern.com/viewtopic.php?id=36651

Now I’m looking for a way of doing something similar, but then grabbing content from an associated TXP website, which uses a different database, this is a bit more tricky it seems :)

Karsten

Offline

#8 2011-12-28 12:25:42

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: Pulling content from one article into another article

Are you trying to pull from an ONIX feed, that exists in another database?

Offline

#9 2011-12-28 12:46:49

sidekarsten
Member
From: Netherlands
Registered: 2011-08-11
Posts: 34
Website

Re: Pulling content from one article into another article

don’t know what ONIX is? not really a programmer, me = archaeologist… :)

Offline

#10 2011-12-28 13:11:24

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

Re: Pulling content from one article into another article

sidekarsten wrote:

Now I’m looking for a way of doing something similar, but then grabbing content from an associated TXP website, which uses a different database

That’s completely different matter. Please open a new topic for that.


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

Offline

#11 2011-12-28 13:23:36

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: Pulling content from one article into another article

ONIX is a data exchange XML format for book publishers.

Offline

#12 2011-12-29 17:32:48

sidekarsten
Member
From: Netherlands
Registered: 2011-08-11
Posts: 34
Website

Re: Pulling content from one article into another article

Ah yeah, I have looked into ONIX once, but I have never really been able to discover what it is, what it does, and why I should need/use it… so in short, the answer to your question is no :)

No this is (as was rightly mentioned) a completely different matter where I want to make several related websites that are unique, but share several things, like basic structure, basic layout (thus forms and css) and I would also like to be able to post publish content… have one site present an overview of recently posted articles on the other site… that sort of stuff… but for this I had already posted other topics:

http://forum.textpattern.com/viewtopic.php?id=37221 and http://forum.textpattern.com/viewtopic.php?id=36909

Offline

Board footer

Powered by FluxBB