Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-07-21 11:31:53

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

[SOLVED] unite article_custom and custom_field

Is there a way to use the new separate and match attributes of if_custom_field to populate an article_custom tag?

ie

<txp:if_custom_field name="c3" separator="," match="any">
<txp:article_custom c3="xx" limit="10" break="li" wraptag="ul">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:if_custom_field>

<txp:if_custom_field name="c3" separator="," match="any">
<txp:article_custom c3="yy" limit="10" break="li" wraptag="ul">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:if_custom_field>

I guess the reason the above does not work is because I would like to use it on all pages.

What I am trying to achieve is have some texts which I relate with comma separated values in the c3 custom_field and display a list of links. The problem I am facing is when I have xx,yy written in the custom_field for which case no articles are displayed.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2011-07-22 06:22:22

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: [SOLVED] unite article_custom and custom_field

I guess what I wish that it could work is <txp:article_custom c3="xx" separator="," match="any" limit="10" break="li" wraptag="ul" />.

Does anyone have any ideas as to how I could achieve something like the above.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2011-07-22 12:59:59

geoff777
Plugin Author
From: Benarrabá Andalucía Spain
Registered: 2008-02-19
Posts: 282
Website

Re: [SOLVED] unite article_custom and custom_field

The <txp:if_custom_field .. outside the <txp:article_custom … tags are redundant … they have to be inside.

The only way I can think of is to use a counter variable with a pair of smd_if tags – the outer for the counter the inner to check the category using smd_if’s list xx|yy setting … make article limit to a figure greater than the number of you could possibly have 99999 or something. Increment the counter if the inner conditional is met.

lol … hope you get what I’m thinking …:-)


There are 10 types of people in the world: those who understand binary, and those who don’t.

Offline

#4 2011-07-22 14:14:22

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: [SOLVED] unite article_custom and custom_field

<txp:article_custom c3="xx" limit="10" section="texts" break="" wraptag="div" class="rels">
<txp:if_custom_field name="c3" separator="," match="any">
<a href="<txp:custom_field name="url" escape="" />"><txp:custom_field name="url_title" escape="" /></a>
</txp:if_custom_field>
</txp:article_custom>

Hi Geoff. You are right re article…

The above seems correct but does not list any articles whose c3 custom field is populated with xx,yy. Can anybody figure out where I might be making a mistake in my thinking?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2011-07-24 12:28:38

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: [SOLVED] unite article_custom and custom_field

I’m now testing the code below, still trying to make sense of the new separator and match attributes of the if_custom_field tag.

<txp:article_custom 
	c3='<txp:if_custom_field name="c3" separator="," match="any" value="xx">xx</txp:if_custom_field>' 
	limit="10"  
	section="texts">

<a href="<txp:custom_field name="url" escape="" />"><txp:custom_field name="url_title" escape="" /></a>

</txp:article_custom>

the code still does not work and returns latest articles from section “texts” regardless of the custom field value.

It shouldn’t be this hard. Can anyone see what I might be doing wrong?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2011-07-24 15:44:29

geoff777
Plugin Author
From: Benarrabá Andalucía Spain
Registered: 2008-02-19
Posts: 282
Website

Re: [SOLVED] unite article_custom and custom_field

This might work?

<txp:variable name="counter" value="0" />
<txp:article_custom section="texts" limit="99999">
  <txp:smd_if field="txpvar:counter" operator="le" value="10">
    <txp:smd_if field="c3" operator="in" value="xx/xx,yy">
       <a href="<txp:custom_field name="url" escape="" />"><txp:custom_field name="url_title" escape="" /></a>
       <txp:variable name="counter" value='<txp:variable name="counter" />+1' />
    </txp:smd_if>
  </txp:smd_if>
</txp:article_custom>

not sure if this will
if it does it’s more flexible …

substitute
<txp:smd_if field="c3" operator="in" value="xx/xx,yy">
with
<txp:smd_if field="c3" operator="contains" value="xx">

if you use adi_calc then that is more elegant for incrementing the “counter”

Sorry it doesn’t use if_custom_field which I see you’ve been testing.
I always use Stef’s plugin … it has bells on it & works!

Last edited by geoff777 (2011-07-24 15:54:50)


There are 10 types of people in the world: those who understand binary, and those who don’t.

Offline

#7 2011-07-24 15:57:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: [SOLVED] unite article_custom and custom_field

Hi goeff and thanks for responding once again,

Just to make myself clearer. I am not trying to count articles but to create relationships between them.

the xx I have in the above code might be confusing. I normally have something like nm (for new media), ae (for art exhibition), ac (for art call), etc.

I have a custom field named c3 which I am adding comma separated values of what I think relates to the page viewed.

The code above works when I have

<txp:article_custom c3="nm" limit="10"  section="texts">
<a href="<txp:custom_field name="url" escape="" />"><txp:custom_field name="url_title" escape="" /></a>
</txp:article_custom>

but it does not list articles whose custom_field contains nm, ac so I thought that using the new custom field attributes would make it work with out of the box tags.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#8 2011-07-24 16:13:17

geoff777
Plugin Author
From: Benarrabá Andalucía Spain
Registered: 2008-02-19
Posts: 282
Website

Re: [SOLVED] unite article_custom and custom_field

The code I wrote doesn’t count articles …?

It should do what you want …


There are 10 types of people in the world: those who understand binary, and those who don’t.

Offline

#9 2011-07-24 16:36:54

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: [SOLVED] unite article_custom and custom_field

Just installed Stef’s plugin and tested your code but it returns no results. It is probably because I am not familiar with the plugin that I can not debug it. Will work on it more.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2011-07-24 22:04:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: [SOLVED] unite article_custom and custom_field

Might your original post work if you use the value attribute? It looks like you haven’t asked it to check against anything yet:

<txp:if_custom_field name="c3" separator="," match="any" value="xx">
   <txp:article_custom c3="xx" limit="10" break="li" wraptag="ul">
      <txp:permlink><txp:title /></txp:permlink>
   </txp:article_custom>
</txp:if_custom_field>

BTW: I don’t see what was wrong with putting if_custom_field outside the article_custom tag in your original past as you have c3="xx" doing the filter by custom_field in your article_custom tag. Your if_custom_field would just check the current article’s custom_field and only output the links if that matched.

In your first example you duplicated the code for c3="yy" too. If you don’t need to explicitly check for those two specific cases, you could also generalize it using smd_each or rah_repeat to split the comma-separated custom_field and use the replace_value as your custom_field content, e.g.:

<txp:rah_repeat value='<txp:custom_field name="c3" />'>
   <h2></txp:rah_repeat_value /></h2>
   <txp:article_custom c3='<txp:rah_repeat_value />' limit="10" break="li" wraptag="ul">
      <txp:permlink><txp:title /></txp:permlink>
   </txp:article_custom>
</txp:rah_repeat>

That would give you link lists for each of your custom_field trigger values whatever they happened to be.


TXP Builders – finely-crafted code, design and txp

Offline

#11 2011-07-25 01:02:14

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

Re: [SOLVED] unite article_custom and custom_field

jakob wrote:

BTW: I don’t see what was wrong with putting if_custom_field outside the article_custom tag in your original past as you have c3="xx" doing the filter by custom_field in your article_custom tag. Your if_custom_field would just check the current article’s custom_field and only output the links if that matched.

Custom_fields, like any other article context tag, can not be used outside an article context. The custom_field would need to be inside an article, it can not be placed directly to page template, nor it filters the list wrapped inside. It filters the contents inside based on the parent article, and only if there is a parent article (the tag is inside an article list, or on individual article page).

Offline

#12 2011-07-25 02:58:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

Re: [SOLVED] unite article_custom and custom_field

Guys, thanks sooo much for your input here but I would like to return to this slightly amended idea for a few seconds and find out why it does not work.

<txp:article_custom 
	limit="10"  
	wraptag="ul" break="li"
	section="texts">
<txp:if_custom_field name="c3" separator="," match="any" value="xx">
<txp:permlink><txp:title /></txp:permlink>
</txp:if_custom_field>
</txp:article_custom>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB