Gossamer Forum
Quote Reply
Yahoo sub cats question
I don't understand the directions in this plug-in. It directs youto place the string SUB0 or SUB1 in the subcategory description fieldbut if I do that how do I include the sub-category description itself???? I knowI'm being really, really dumb here but if someone could explain where I'm notgetting it I would be grateful.

Smokey
Quote Reply
Re: [biglouis] Yahoo sub cats question In reply to
OK, I realise what the failure of understanding is and I've got it working. The "about" file is not entirely obvious, GT may want to make it a bit clearer.
Quote Reply
Re: [biglouis] Yahoo sub cats question In reply to
I'm sure I've posted a few hacks as well, that let you do things such as show the subcategories on separate lines, snd such. This is on my list of things to update when my sites come back on-line.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Pugdog

Thanks for the response. There is one modification I would like to make and I wonder if you have already done this?

I'd like to show the subcats AND a description on the home page. As you have to overwrite the description field with the subcats tag (e.g. SUB0/SUB1) it occurs to me that you can use the contents of the META DESCRIPTION field as the text for the description. I only need to figure out where the display of the individual categories takes place and at the meta field into the routine. Any ideas? Or have you already done this?

Cheers

Smokey
Quote Reply
Re: [biglouis] Yahoo sub cats question In reply to
Already done :)

That is how I had the LinksSQL FAQ site set up. :)

I need to try to dig out that script, but that may be what I work on today, since it should be a quick fix to the 2.0x code.

Oddly, it wasn't as trivial as it might seem -- it took a bit of trial and error to make it work correctly.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [biglouis] Yahoo sub cats question In reply to
Ok,

Here is the updated YahooSubcats program, as it was running on the Links SQL FAQ site.

You can use a command like:

Update prefix_Category set Description = concat('SUB0 ', Description)

to quickly update all your categories.

This modification stemmed from the need to not only have descriptions, but also to have the categories listed one-per-line, rather than all on one line, which would often wrap oddly, and look pretty bad, IMHO -- at least on my sites.

BTW... this is a simple install, if you don't like it, just reinstall the old version -- or edit the YahooSubcats.pm file to change the formatting.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
BTW:

There is a stylistic thing (problem) if you use the Description field in any of your templates. It's no different than the original YahooSubcats, in that SUB0 will show in front of the description.

I got around that by adding a Long_Description or Desc_Long field to the Category table, and initially copying over the contents of the Description field:

Update Category set Desc_Long = Description

Then, in the templates I used Desc_Long where I wanted more descriptions (such as at the top of the category pages) and used Description to keep a short 1-line description to be used in the subcategory.html file.

It works well, and is somewhat better than trying to have one field do it all.

BTW2: I found this old message http://gossamer-threads.com/...orum.cgi?post=145501 that explains a bit why I made some of the formatting changes, and what they do. Of course, the example link won't work until my sites come back up :)



PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Dec 31, 2001, 7:03 AM
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Pugdog

Thanks very much for this. Greatly appreciated. I will play with it tomorrow as it is near my bed time here in Jolly Old England.

I'll tell you how I get on with it (and when the site is up and running you'll be able to see for yourself!).

Cheers

Smokey
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Pugdog

Got it up and running and I like it! Had to work out in the .pm file how to remove the vertical list (e.g. <br> tags) so I could get a line of subcat links. There are two additional features I'd like to create:

i) I'd like the subcats to appear above the description;

ii) I'd like a subcats list to appear only where subcats exist (e.g. at present it will print out the name of the category again if no subcats exist).

If you have the time to give me some pointers on where in the code I can fix this I'd be very grateful.

Thanks again for all your help

Smokey/Darth
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Doh! Another "Homer" moment. Of course, the easiest way to avoid displaying an empty subcats list is not use the subcats tag in that particular category. Sorry if you wasted any bandwidth on that one! I'd still like to display the list of subcats before the description, though.

Cheers

Smokey/Darth
Quote Reply
Re: [biglouis] Yahoo sub cats question In reply to
Ok,

I specifically made it print out the name of the subcategory, for formatting reasons (see the referenced old post above).

You can remove that line in the .pm file, I don't have it here to point out where.

Also, you can change the order of the description/cat_list toward the end of the script, where it concactenates them, just reverse it. I think that is all that is needed. I'll look at it later and check :)




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Pugdog

I'm damn close but my Perl skills are too rudimentary to make the final change. Am I right in assuming this code snippet formats the text which is displayed per category:

if ($cat_r->{Description}=~/SUB[01]/) {
if (length $cat_r->{Description} > 4) {
$cat_r->{Description} .= "<br>" . $description
} else {
$cat_r->{Description} .= $description
}


If I am right - then my only problem is that I do not understand how to reverse the concatentation so that the contents of $description precede the category description text.

Its also driving me nuts because I am plowing through Perl reference texts but I'm not seeing the light. Of course I could be completely wrong in my assumptions.

If you can shed some light on the subject (actually, if you can give me the statements to drop into the script!) I would be grateful.

Cheers

Smokey
Quote Reply
Re: [biglouis] Yahoo sub cats question In reply to
Ok,

At this point $description contains the list of linked subcategories (it's a bit confusing, but it's a hold over from the
original plugin, where that was the only description.


if ($cat_r->{Description}=~/SUB[01]/) { ## if the description contains SUB0 or SUB1
if (length $cat_r->{Description} > 4) { ## if the description doesn't _only_ contain SUB0 or SUB1
$cat_r->{Description} .= "<br>" . $description ### add a <BR> to the FRONT of the category list to set it off from the description.
} else {
$cat_r->{Description} .= $description ## otherwise, just add the category list.

}



To do what you want to do, you'd need to change the line with the <BR> to:

$cat_r->{Description} = $description . '<BR>' . $cat_r->{Description};

NOTE: the .= becomes an = since you are no longer appending, but simply assigning a totally new value.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Pugdog

That works perfectly. Thanks a million. I knew it was somewhere in that routine but it never ocurred to me to try the code solution you provided.

All working exactly the way I want it to.

Once again, many thanks

Smokey
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
You should probably use:

if ($cat_r->{Description}=~/^SUB[01]$/) {

Just incase someone happens to have a description with SUB0 or SUB1 in for whatever reason, however unlikely it may be.

Last edited by:

RedRum: Jan 1, 2002, 11:53 AM
Quote Reply
Re: [RedRum] Yahoo sub cats question In reply to
Quote:

if ($cat_r->{Description}=~/^SUB[01]$/) {


Problem is that will only find descriptions that are exactly SUB0 or SUB1

The original logic assumed that the description would only be SUB0 or SUB1. Odds are small this sort of thing will happen, and it can be affected by trailing spaces.

I'm not sure if (^SUB[01]|SUB[01]$) would do what is expected, or if you'd have to use two different tests, which is what is usually usgested or shown as an example:

if ( ( $cat_r->{Description}=~ /^SUB[01]/ ) or ( $cat_r->{Description}=~ /SUB[01] *$/ ) ) {


is an attempt to match the begining of the line, or end of line, with any number of trailing spaces. Not tested, but it's the idea.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
>>if ( ( $cat_r->{Description}=~ /^SUB[01]/ ) or ( $cat_r->{Description}=~ /SUB[01] *$/ ) ) {
<<

How about:

if ($cat_r->{Description}=~ /^\s*SUB[01]\s*$/) {

Quote Reply
Re: [RedRum] Yahoo sub cats question In reply to
\s matches any whitespace - including tabs and newlines, and that might not be the behavior you want.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
Surely you are trying to match the description field with SUB0 or SUB1 in?

...so using \s would be fine incase someone enters:

--
SUB0
--

or...

--

SUB0
--

or
Code:
--
SUB0
--
Quote Reply
Re: [RedRum] Yahoo sub cats question In reply to
Well, that's not really how it seems to work. Most people have their categories empty, and intially set the description to 'SUB0' or 'SUB1' doing something like:

update Category set Description = 'SUB0'

Problem comes with taking out the white space that was intentionally added.

The most "correct" way to do it, would probably be to match SUB[01] when not preceeded by any non-space characters \S (begining of string), or not followed by any non-space characters (end of string)




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Yahoo sub cats question In reply to
You have to allow for user error though or "newbiness" by creating an appropriate regex to handle such fluctuations rather than assuming the formatting will be perfect.

Last edited by:

RedRum: Jan 1, 2002, 4:10 PM
Quote Reply
Re: [RedRum] Yahoo sub cats question In reply to
My point exactly.

Using \s _prevents_ a user from allowing a trailing whitespace character, which might be something needed in order to assure proper HTML formatting. Even using ' *' will remove the trailing whitespace (space) which might alter the formatting options.

Rather than cripple the ability of the people who need extra formatting, why not make the people entering the bad codes fix them?

Very simply, SUB0/1 should be the first or last thing in the description field, and that is a really simple thing for people to do, and to ensure. It's a lot easier to do the search/replace on the database a single time, than to try to do it each and every time that record is displayed.

Without creating some sort of very complex routine to try to take various options into account, the simple solution initially proposed, or a simple check for begining or ending is more than sufficient. Anything beyond that actually _REMOVES_ flexibility and potential from the routine.




PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.