Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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
Member
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: 12,521
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.

Hire 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

#25 2011-07-05 17:33:09

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

Re: Using glz_custom_fields and categories to create a tagging system

This is working wonderfully, thanks, Stef. Is there a way to check if the value is NOT empty? I’m running into a problem with the way I’m doing it right now, which is to check if it IS empty. Here’s what I’m doing:

<txp:smd_switch item="?coverageclient">
   <txp:smd_case type="empty">
   </txp:smd_case>
      <txp:article_custom section="coverage" coverageclient='<txp:variable name="coverageclient" />' form="article_listing" limit="999" />
</txp:smd_switch>

The thing is, if there are articles that have no client (or coverage type, or media outlet, etc) associated with them (as there are in some cases), those articles are showing up on the page regardless of whether anything is selected. So instead of getting a list of articles from CNN, I am getting a list of articles from CNN, followed by all the ones that have one or more empty values for some of the fields.

Any ideas?


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