Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-08-16 03:56:31

progre55
Member
Registered: 2006-05-02
Posts: 668

Link to A List of Articles Based on Custom Field

This one is so simple, I cannot believe I am asking, but how can I create a link so that it will pull up a list of all articles with the same custom field —- I am not asking how you display a list which I know —-

progre55

Last edited by progre55 (2011-08-16 03:57:02)

Offline

#2 2011-08-16 04:09:56

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: Link to A List of Articles Based on Custom Field

Install adi_gps, make a link like this in your template or form:

<a href="<txp:site_url />?foo=bar">All articles with custom field Foo set to "Bar"</a>

Then wherever you want the articles to appear:

<txp:adi_gps name="foo" quiet="1" />
<txp:if_variable name="foo">
  <txp:article_custom foo='<txp:adi_gps name="foo" />' status="live">
    <h3><txp:permlink><txp:title /></txp:permlink></h3>
  </txp:article_custom>
</txp:if_variable>

That should do it…

Last edited by maruchan (2011-08-16 04:10:39)

Offline

#3 2011-08-16 12:32:27

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Link to A List of Articles Based on Custom Field

Thank, maruchan. I will test out and let you know.

progre55

Offline

#4 2011-08-16 20:41:02

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Link to A List of Articles Based on Custom Field

maruchan:

The first part is self explanatory — a little confused on the second part “wherever you want the articles to appear: <place this code>” — how does it know which template to use or where to go when the link is selected?

I tried placing it sin several locations with no success —-

progre55

Offline

#5 2011-08-16 20:51:19

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: Link to A List of Articles Based on Custom Field

So if your link url is example.com?foo=bar then you want that code in your default template. If your url is example.com/section-one?foo=bar then you want to put that code in the template that section-one uses (as long as you are using Textpattern’s clean URLs).

Or to put it another way, if this code needs to go in a certain section’s page template, make sure that you are adding ?foo=bar to a URL that contains that section’s name.

Here’s the code above but with a bit more error checking:

<txp:adi_gps name="foo" />
<txp:if_variable name="foo">
  <txp:article_custom foo='<txp:adi_gps name="foo" />' status="live">
    <h3><txp:permlink><txp:title /></txp:permlink></h3>
  </txp:article_custom>
<txp:else />
  <p>The variable has not been set. Please check your URL.</p>
</txp:if_variable>

BTW remember: No spaces or dashes (-) in custom field names or values. letters, numbers, underscores only.

Last edited by maruchan (2011-08-16 20:52:20)

Offline

#6 2011-08-16 21:33:35

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: Link to A List of Articles Based on Custom Field

maruchan:

Success … but …

I used this:

<a href="<txp:site_url />?Country=USA">All articles with custom field Country set to "USA"</a>
<txp:adi_gps name="Country" />
<txp:if_variable name="Country">
  <txp:article_custom Country='<txp:adi_gps name="Country" />' status="live" limit=50>
    <h3><txp:permlink><txp:title /></txp:permlink></h3>
  </txp:article_custom>
<txp:else />
  <p>The variable has not been set. Please check your URL.</p>
</txp:if_variable>

The above returned the articles as expected — which is a good thing …

Now, what I am trying to figure out is how I can get it to return information for custom fields that have spaces and data that has spaces.

I am using glz_custom_fields This allows me to create names that have spaces. It would be very difficult because of the state of project to go back and have to change all the custom fields.

Also, as an example,I have a field like Author — in this field it has first & last name (with space) — I was unable to get a return using that field —-

Any suggestions./guidance would be appreciated —-

progre55

Last edited by progre55 (2011-08-16 21:40:11)

Offline

#7 2011-08-16 21:52:54

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: Link to A List of Articles Based on Custom Field

No idea. You might want to start a new topic on using spaces in custom fields, and explain your authors example.

You can use bot_cf_titles to rename CF titles. But for values…no idea.

Last edited by maruchan (2011-08-16 21:53:31)

Offline

#8 2011-08-17 16:34:57

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Link to A List of Articles Based on Custom Field

The space, when put in a url variable, may be encoded or dropped. I’d bet a tag trace from the results page would help solve the problem.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#9 2011-08-18 08:33:01

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

Re: Link to A List of Articles Based on Custom Field

I never used adi_gps so I cannot comment but from the code above, i cannot see where the variable has been declared.

what about

<txp:variable name="hascountry" value='<txp:custom_field name="Country" />' />
<txp:if_variable name="hascountry" value="">
  <p>The variable has not been set. Please check your URL.</p>
<txp:else />
  <txp:article_custom Country='<txp:custom_field name="country" />' status="live" limit=50>
    <h3><txp:permlink><txp:title /></txp:permlink></h3>
  </txp:article_custom>
</txp:if_variable>

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-08-18 09:42:16

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

Re: Link to A List of Articles Based on Custom Field

I never used adi_gps so … I cannot see where the variable has been declared.

Yiannis, the nice thing about adi_gps is that it stores the requested url value in a txp:variable for you, which is why it is not declared.

Like Marc already mentioned, I see no way around custom_field names with spaces, or those that collide with other attributes used with txp:article_custom. txp:article_custom will regard the individual worlds of the custom field name as separate attributes, and probably also complain that they do not exist or are missing a value.

I’ve not tested it but I imagine that txp:article could accept values encoded as “Dominican%20Republic” (or that one could search and replace these easily before inserting them as an attribute-value in txp:article_custom).


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB