Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-05 20:55:31

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Displaying an article depending on another one?

Hi everyone,

I’m using a template with two (in this case) articles on one page.
I’m creating a list in a section (with it’s own template) where user’s can find articles sorted by categorys.
They can choose one (permlink) and click on it.
Since the articles are in another section, it will open and replace the tag with the article (article-id is in the url).

I want the 2nd article to be displayed fitting to the first one.
I tried to add another ID by seperating them with , but it doesn’t work for me.
The first article-ID is used by both tags, so I have twice the same article on the same page.

Is it anyhow possible to connect two articles, without creating new categorys for all articles I want to connect.

It would be ok to add the ID of the second article to a customfield while writing the first one, but how can I forward this information for two articles and how can I force TXP to show the first one replacing one tag and the second one replacing another tag.

I hope it is possible to understad what my aim is. If not, please tell me what’s confusing about my idea and I will do my best to explain :)

+sorry for my freaking english as usual

regards,

RipvanFish

Last edited by RipvanFish (2009-08-05 20:56:57)

Offline

#2 2009-08-05 22:29:23

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying an article depending on another one?

If I understand you correctly – and I’m not sure about that ;) – you want two articles on an individual article page. This is only possible using <txp:article_custom /> for the second article, because the <txp:article /> tag will only display the current article (the one that is in the url), as you’ve already noticed.
Yes, you can do it using a custom field. Enter the id of the article that you want to be the second article in a custom field of the main article. Then add this in the article form that you use to display the main article:

<txp:article_custom id='<txp:custom_field name="nameofyourcustomfield" />' form="yourform" />

Adding this after the (title, body etcetera) tags that display the first article will display the second article after the main article. Should you want the second article to appear somewhere else on the page, for instance in a sidebar, you need to use a second <txp:article /> tag, using an article form that contains the above article_custom tag, or place this code where you want to display the second article:

<txp:if_individual_article>
<txp:article_custom id='<txp:custom_field name="nameofyourcustomfield" />' form="yourform" />
</txp:if_individual_article>

Last edited by els (2009-08-05 22:33:40)

Offline

#3 2009-08-06 10:55:51

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Re: Displaying an article depending on another one?

Hello Els,

thank you (!!!) for answering.
Yes, I am trying to display this second article (e.g. by using a custom_field with the ID of the second article) in a box (another <div>-container) wich is above the box for the first article in my template.
I tried your suggestion, but it displays me all articles, like i would have left the ID=”“ like this empty.
I even tried to set a var in the first articles form and use it later for the second one, but that isn’t working too :(

Offline

#4 2009-08-06 10:59:54

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Displaying an article depending on another one?

RipvanFish wrote:

I tried your suggestion, but it displays me all articles, like i would have left the ID=”“ like this empty.
I even tried to set a var in the first articles form and use it later for the second one, but that isn’t working too :(

Without you posting your code or tag trace we can’t really help.

Offline

#5 2009-08-06 11:10:06

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Re: Displaying an article depending on another one?

<div id="infobox">
	<div class="area area-blue">
		<div class="area-inner">
      <txp:if_individual_article>
        <txp:article_custom id='<txp:custom_field name="nameofyourcustomfield" />' form="yourform" />
      </txp:if_individual_article>
		</div>
	</div>
</div>
<div id="content-wrapper"><div id="content">
  <txp:article form="article_content_only_CUSTOM" />
   <div id="footer">

That is my template. The “main”-article is displayed by id (URL) with the second article-tag. Now I want TXP to replace the first one with the ID added in a custom_field attached to the main-article.

Offline

#6 2009-08-06 12:32:09

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

Re: Displaying an article depending on another one?

Have you set up the custom field, given it a name, and put an ID value in it?


Code is topiary

Offline

#7 2009-08-06 15:09:13

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Re: Displaying an article depending on another one?

jsoo schrieb:

Have you set up the custom field, given it a name, and put an ID value in it?

Of course i set it up and put an ID value in it.

Offline

#8 2009-08-06 15:27:47

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

Re: Displaying an article depending on another one?

Which name did you assign to the custom field?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#9 2009-08-06 15:45:47

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Re: Displaying an article depending on another one?

It is the 4th custom_field named “sublink”.

Offline

#10 2009-08-06 15:47:04

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

Re: Displaying an article depending on another one?

RipvanFish wrote:

Of course i set it up and put an ID value in it.

Just checking! Based on the code you showed I wasn’t sure. Did you use the name of the custom field as the name attribute of your custom_field tag, and use an appropriate value for the form attribute of your article_custom tag?

It’d save time if you posted or made available a tag trace, as Gocom suggested.


Code is topiary

Offline

#11 2009-08-08 17:08:26

RipvanFish
Member
Registered: 2009-07-09
Posts: 35

Re: Displaying an article depending on another one?

@jsoo: I know you’re just checking, wasn’t my intention to offend you :) I’m thanful for every kind of help I can get :)

@Els: What you wrote was working 100% fine, I was just too dumb to get your idea. I took a little break and now it is working like you thought it should! Thanks for your quick and effective help :D

+ Thanks to anyone else trying to help me out :)

Offline

#12 2009-08-08 17:59:05

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying an article depending on another one?

RipvanFish wrote:

now it is working like you thought it should!

Glad it helped :)

Offline

Board footer

Powered by FluxBB