Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2011-06-19 01:00:15

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

Re: Using glz_custom_fields and categories to create a tagging system

Could it be the hyphen in the custom field’s name?


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

Offline

#14 2011-06-19 02:01:52

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Using glz_custom_fields and categories to create a tagging system

I think that might have been the main problem. I had it working for a second, made a change to the article tags for that page and now it’s not working again. hehe. * sigh *

This is getting really frustrating. It seems like getting the articles on the page should be the easiest part, but I’m not having any luck. Even when I try testing the functionality of

<txp:article section="coverage" coverageclient="Example" form="article_listing"  />

or

<txp:article_custom section="coverage" coverageclient="Example" form="article_listing"  />

I don’t get a listing of the articles with the value “Example” in the custom field “coverageclient”. Which means it’s falling apart at a deeper level than just the variables, etc.

Last edited by frickinmuck (2011-06-19 02:29:10)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#15 2011-06-19 05:05:18

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Using glz_custom_fields and categories to create a tagging system

OK, I’ve finally figured out what’s going wrong. It works beautifully if I hard-code the rah_repeat values and manually input the glz custom field select options in the back end, as in:

Example 1

<h1 class="sidebar-title">View by Coverage Type</h1>
<form class="coverage-selector" action='<txp:page_url type="request_uri" />' method="get">
<select name="coveragetype2" onChange="this.form.submit();">
<txp:if_variable name="coveragetype2" value="">
<option value=""> </option>
<txp:else /><option value="">All</option>
</txp:if_variable>
<txp:rah_repeat value='Television,Blog'>
<option <txp:if_variable name="coveragetype2" value='<txp:rah_repeat_value />'>selected</txp:if_variable> value='<txp:rah_repeat_value />'><txp:rah_repeat_value /></option>
	<txp:rah_repeat_value />
</txp:rah_repeat></select>
<noscript><input type="submit" value="Go!"></noscript>
</form>

Which tells me that for some reason, it’s not responding well to the custom field/category/glz script thing. Here’s the code for that part:

Example 2

<h1 class="sidebar-title">View by Client</h1>
<form class="coverage-selector" action='<txp:page_url type="request_uri" />' method="get">
<select name="client" onChange="this.form.submit();">
<txp:if_variable name="coverageclient" value="">
<option value=""> </option>
<txp:else /><option value="">All</option>
</txp:if_variable>
<txp:rah_repeat value='<txp:category_list parent="client" break="," exclude="client"><txp:category title="1" link="0" /></txp:category_list>'>
<option <txp:if_variable name="coverageclient" value='<txp:rah_repeat_value />'>selected</txp:if_variable> value='<txp:rah_repeat_value />'><txp:rah_repeat_value /></option>
	<txp:rah_repeat_value />
</txp:rah_repeat></select>
<noscript><input type="submit" value="Go!"></noscript>
</form>

I can post a tag trace if anyone would be willing to take a look at it. I can’t see anything in the HTML output that looks off. As far as I can tell, it should be working both ways, but it isn’t.

Last edited by frickinmuck (2011-06-19 06:04:08)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#16 2011-06-19 06:43:33

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Using glz_custom_fields and categories to create a tagging system

Upon further investigation, and digging into the database it seems that the custom script for the drop down for the custom fields is using the name of the category instead of the title, which would then not match the output for my lists on the public side. Is there any way I can get the script to use the category title instead of the name? I’m no PHP master…

<?php
function list_clients($custom_field, $custom_id, $custom_value) {
    $categories = array();
    $query = safe_rows('name, title', 'txp_category', 'parent like "client"');
    foreach ($query as $category)
        $categories[$category['name']] = $category['title'];
    return glz_selectInput($custom_field, $custom_id, $categories, $custom_value, "");
}
?>

Edit: that’s definitely the problem. When I change the form to this:

<h1 class="sidebar-title">View by Client</h1>
<form class="coverage-selector" action='<txp:page_url type="request_uri" />' method="get">
<select name="coverageclient" onChange="this.form.submit();">
<txp:if_variable name="coverageclient" value="">
<option value=""> </option>
<txp:else /><option value="">All</option>
</txp:if_variable>
<txp:rah_repeat value='<txp:category_list parent="client" break="," exclude="client"><txp:category link="0" /></txp:category_list>'>
<option <txp:if_variable name="coverageclient" value='<txp:rah_repeat_value />'>selected</txp:if_variable> value='<txp:rah_repeat_value />'><txp:rah_repeat_value /></option>
	<txp:rah_repeat_value />
</txp:rah_repeat></select>
<noscript><input type="submit" value="Go!"></noscript>
</form>

(in other words, set the dropdown on the front end to use the category name instead of title) it works like a dream. Anyone a PHP guru who can help me tweak that script so it uses the title instead?

Last edited by frickinmuck (2011-06-19 06:51:46)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#17 2011-06-19 07:02:36

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

Re: Using glz_custom_fields and categories to create a tagging system

frickinmuck wrote:

Anyone a PHP guru who can help me tweak that script so it uses the title instead?

If you want to change glz_custom_field to list and store titles instead of names, you can change $category['name'] to $category['title'] in the PHP script. I.e.

function list_clients($custom_field, $custom_id, $custom_value) {
	$categories = array();
	$query = safe_rows('title', 'txp_category', 'parent="client"');
	foreach ($query as $category)
		$categories[$category['title']] = $category['title'];
	return glz_selectInput($custom_field, $custom_id, $categories, $custom_value, "");
}

Last edited by Gocom (2011-06-19 07:02:50)

Offline

#18 2011-06-19 07:54:37

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Using glz_custom_fields and categories to create a tagging system

Thanks!


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#19 2011-06-19 12:04:49

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Using glz_custom_fields and categories to create a tagging system

Thanks everyone for the help – things are functioning beautifully now, and when I’m done this project I’m going to put this together into a Tutorial for TXP Tips so other people can benefit from it.

I just have one more thing I need to sort out – how do I incorporate several parameters on a page without causing conflicts? I know I’m doing it wrong right now… here’s my code:

   <txp:adi_gps name="coverageclient" quiet="1" />
        <txp:adi_gps name="coveragemediaoutlet" quiet="1" />
        <txp:if_variable name="coverageclient" value="">
        <txp:if_variable name="coveragemediaoutlet" value="">
        <!--if no url queries-->
        <txp:else />
        <txp:article_custom section="coverage" coverageclient='<txp:variable name="coverageclient" />' form="article_listing"  />
        <txp:article_custom section="coverage" coveragemediaoutlet='<txp:variable name="coveragemediaoutlet" />' form="article_listing"  />
        </txp:if_variable>
        </txp:if_variable>

I will eventually need to have 4 parameters on here – Coverage Type, Client, Media Outlet and Issue. People will be sorting using one parameter at a time, so it will be Coverage Type OR Client OR Media Outlet OR Issue

Thanks again, everyone!

Last edited by frickinmuck (2011-06-19 12:07:16)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#20 2011-06-19 12:18:48

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Using glz_custom_fields and categories to create a tagging system

@frickinmuck – that would be great, please submit to TXP Tips when you are ready!

Offline

#21 2011-06-19 17:35:07

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: Using glz_custom_fields and categories to create a tagging system

I think you would need conditional nesting. But if I correctly understand this, the same tag can’t be nested. So I suppose you should do it in another way…

Maybe this could help?

Anyway this is what I’ll try if conditional nesting would work:

   <txp:adi_gps name="coverageclient" quiet="1" />
        <txp:adi_gps name="coveragemediaoutlet" quiet="1" />
        <txp:adi_gps name="coveragetype" quiet="1" />
        <txp:adi_gps name="coverageissue" quiet="1" />
        <txp:if_variable name="coverageclient" value="">
        <txp:if_variable name="coveragemediaoutlet" value="">
        <txp:if_variable name="coveragetype" value="">
        <txp:if_variable name="coverageissue" value="">
        <!--if no url queries-->       
        <txp:else />
        <txp:article_custom section="coverage" coveragissue='<txp:variable name="coverageissue" />' form="article_listing"  />
        </txp:if_variable>
        <txp:else />
        <txp:article_custom section="coverage" coveragetype='<txp:variable name="coveragetype" />' form="article_listing"  />
        </txp:if_variable>
        <txp:else />
        <txp:article_custom section="coverage" coveragemediaoutlet='<txp:variable name="coveragemediaoutlet" />' form="article_listing"  />
        </txp:if_variable>
        <txp:else />
        <txp:article_custom section="coverage" coverageclient='<txp:variable name="coverageclient" />' form="article_listing"  />
        </txp:if_variable>

Offline

#22 2011-06-19 17:50:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Using glz_custom_fields and categories to create a tagging system

Zanza wrote:

the same tag can’t be nested

That’s a very old page. Ignore it (it needs deleting). Same-sex tags can be nested as of TXP 4.0.7.

Using bunches of nested conditionals like this can become unwieldy so if you’re not averse to plugins (sorry, I haven’t been following this thread so I’m not sure if this is a “can it be done in fewest core tags” request) then you have two possible options from my plugin arsenal:

  1. smd_if, using the ‘and’ logic to conditionally test if more than one thing at once is true, or the ‘or’ logic to test if one of several things are true
  2. as you say, smd_multi_choice to do a select-case style of selection where you can test one variable multiple times in succession and take action depending on which one it matches

Not sure if either fit the bill in this case.

Last edited by Bloke (2011-06-19 18:05:57)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#23 2011-06-19 18:13:28

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: Using glz_custom_fields and categories to create a tagging system

Oh, ok, thanks for the clarification, Stef. Let’s see what fits frickinmuck problem better.

Offline

#24 2011-06-19 18:13:56

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Using glz_custom_fields and categories to create a tagging system

I will give those a try. That’s just the sort of thing I need to get started. I want a simple way to check the variables and then do whatever according to the outcome. Thanks!


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

Board footer

Powered by FluxBB