Gossamer Forum
Home : Products : Links 2.0 : Customization :

Adding Fields to 2.0

Quote Reply
Adding Fields to 2.0
Are there any guides out there that show you how to add fields to Links 2.0? If not could someone please walk me through the basics? Is it any different than adding fields to Links 1.11?

Thanks!
Quote Reply
Re: Adding Fields to 2.0 In reply to
There have been a variety of posts, but I'll get you started.

I use templates for Links 2.0

You basically need to edit the file links.def

There you will see
%db_def = (
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 150, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
MemberStatus => [5, 'alpha', 0, 500, 0, '', ''],

I don't know how this will look like on the forum, but I added a new field AltCategories. It is the 5th field. The 3rd and 4th parameter are sizes of the field. The 5th identifies whether it is required (=1) or not required (=0), the 6th is the default value (leave ' ' if you want it blank).

So add a field and if it is not the last one, you need to put a comma after the last bracket ]

Then go down to :

# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_category = 4; $db_modified = 3; $db_url = 2;
$db_hits = 9; $db_isnew = 10; $db_ispop = 11; $db_memberstatus = 5;

You need to assign each field with its appropriate id #.

You can then add select fields by just copying the format of isNew, is Popular:

%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
MemberStatus => 'Associate,Gold,Premier',

and this will show up in your admin options as a select field.

Hope that helps.
Quote Reply
Re: Adding Fields to 2.0 In reply to
Actually, the field added was MemberStatus and not AltCategories in the above message.
Quote Reply
Re: Adding Fields to 2.0 In reply to
Is that it? I dont need to mention the new field anywhere else in the scripts for it to show up? Because in 1.11 it was quite an operation.

I'll try it out, thanks alot for your help!
Quote Reply
Re: Adding Fields to 2.0 In reply to
Yes, that's about it. Alex has made it easy for us. If you want to add the new field that you've created in your database, just copy the same format as the other fields.

If you want it to show up in your links, then you must edit the links template file. Just add it in like the other fields eg. <%newfield%>

You can also use "if" tags,

<%if newfield%>
then add your field or a picture to show if there is a value for newfield and close it with
<%endif%>

So if there is no value for newfield, then nothing shows up. I hope that helps. Once you get the hang of it, it's quite easy.
Quote Reply
Re: Adding Fields to 2.0 In reply to
So if I already have 1,500 existing links in my db and I add a field to the end...do I need to go through and add anything to the end of the existing links in the db?

so if it end yes|24|yes| (or whatever it is)
do I need to make it yes|24|yes&#0124; &#0124;
??
Quote Reply
Re: Adding Fields to 2.0 In reply to
Zelph,

Yes, you would have to add it to all the links currently in the database. Luckily, you could modify the upgrade_beta.pl script that is included with Links v2.0 to do that for you. Just be sure to run it in your data directory and then, rename links2.db to links.db when you are satisfied with the results.

In upgrade_beta.pl, just change print DBOUT "$_|Yes\n"; to print DBOUT "$_|\n"; and it will add an empty field to the end of each record. If you want some default value to be in the new field, then change it to print DBOUT "$_|value\n";, where value is what you want in the field. The new database will be in links2.db.

By the way, the information in that script about changing the permissions of your Hits directory to 777 is erroneous. It should be the data directory that has those permissions and there is no real reason to change the permissions back to 755 as it says unless you do not password protect your admin directory.

I hope this helps.

[This message has been edited by Bobsie (edited March 11, 1999).]
Quote Reply
Re: Adding Fields to 2.0 In reply to
I got this to work out great. Instead of adding a "MemberStatus" to links def I added "Page2" which allows a person the ability to add a second page. I can add this second page in the admin directory and it works out fine, but I need to know how to add this option the add.cgi or add.html so a user can add it too.
-Timmyt
Quote Reply
Re: Adding Fields to 2.0 In reply to
In the form used for an add (also for a modify), just include an <input> tag for the new field. That's all there really is to it. Of course, you would also want to include it on the failure pages as well.
Quote Reply
Re: Adding Fields to 2.0 In reply to
So it would look like this Bobsie?
<%if isDemo%>
<small><a href="<%Demo%>">Demo </a></small>
<%endif%>
Thanks again for all your help
Quote Reply
Re: Adding Fields to 2.0 In reply to
Umm... no, that's not it. You indicated you needed a way for someone to include Page2 as part of a resource addition. What I said was, you need to add an <input> tag to the form in add.html and again in add_error.html and possibly the modify templates too. An <input> tag should look something like this:

Quote:
<input type="text" name="Page2" value="">

I hope that clarifies what I said.

[This message has been edited by Bobsie (edited March 30, 1999).]
Quote Reply
Re: Adding Fields to 2.0 In reply to
If the field is a combination of "numbers" and "alphabets" which one to use? Can I just leave it as 'alpha'? Which one to use when?

An explanation is appreciated.
Quote Reply
Re: Adding Fields to 2.0 In reply to
Use "numer" if the field is to be all numbers, or numeric. Otherwise, use "alpha" which actually stands for alphanumeric.
Quote Reply
Re: Adding Fields to 2.0 In reply to
I just used these instructions to create a new field called "isVeg", to mark entries in my database that are vegetarian. I modelled it on the "isNew" field. Unfortunately, all the links on the What's New page are marked "Veg", even though when I go to modify the records some of them clearly have "isVeg" set to "No".

Here's the Links page: http://www.jill.net/links/

Thanks in advance for your help,

Jill
Quote Reply
Re: Adding Fields to 2.0 In reply to
Jill,

It sounds like what you did was to set up isVeg as a yes/no select field, and then in your templates you called it using
<%if isVeg%>
vegetarian
<%endif%>
or something very much like that. Is that right?
Using the <%if%> statements in templates asks the database, "Is their any information in this field?" and if there is any at all, it returns true. So when you have "No" in the field, that is still text, and it displays.

It would work better for you to make isVeg a checkbox field. If there is a checkmark in the box, it will print "Vegetarian" or whatever your text is. If there is no checkmark in the box, it will not print anything.

Explanation of how to add a checkbox field is at www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/000520.html

Hope this is what you need to know.
Phoenix

[This message has been edited by phoenix (edited April 11, 1999).]
Quote Reply
Re: Adding Fields to 2.0 In reply to
For site_html_templates.pl > sub site_html_link try adding:
Code:
($rec{'isVeg'} eq 'Yes') ? ($rec{'isVeg'} = 1) : (delete $rec{'isVeg'});

If you did everything else just like 'isNew' this is probably the missing ingredient. I think this keeps anything but a 'Yes' in the 'isVeg' field from printing 'Veg'.

[This message has been edited by Dave (edited April 11, 1999).]
Quote Reply
Re: Adding Fields to 2.0 In reply to
Thanks to you both!

Yes, Phoenix, that's exactly what I did! I'm not much of a hacker, really...

and thanks, Dave - your solution works perfectly!

Jill
Quote Reply
Re: Adding Fields to 2.0 In reply to
Now that I have ad a new field, How do I set it so that people could search using that field too.

Thanks

lancier
Quote Reply
Re: Adding Fields to 2.0 In reply to
In the following array, @search_fields, in your links.def file, add the number of the field number of your new field.

Example:

Code:
@search_fields = (1,2,6,17,19,21);

Let's say that 21 is the number of your new field, add it to the value string.

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Adding Fields to 2.0 In reply to
There's a new reference in the FAQ 2.0 that talks about adding fields to the database. The code actually references your new links.def or categories.def in what else to add.

Check it out

------------------
www.webgotcha.com
[b]admin@webgotcha.com[/b]
Quote Reply
Re: Adding Fields to 2.0 In reply to
Hello

I got the field added. But I can't seem to display that on the website. I edited the templated page link.html with the following:

<%if isfile%>
<%file%>
<%endif%>

But the field "file" is not showing up in the category pages. What do I have to do?? Please help.

Quote Reply
Re: Adding Fields to 2.0 In reply to
DON'T QUOTE ME ON THIS BECAUSE I USE SITE_HTML.PL
BACKUP SITE_HTML_TEMPLATES.PL FIRST


In site_html_print_cat in site_html_templates, find this:


# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;


change to....


# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|<dd>$file</dd>|;
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;


From Paul Wilson.
http://www.audio-grabber.com
Music Directory
Quote Reply
Re: Adding Fields to 2.0 In reply to
Hello

Thanks but That doesn't seem to work. I added it but it still doesn't work. Any other suggestions?

Ericz

Quote Reply
Re: Adding Fields to 2.0 In reply to
In Reply To:
I got the field added. But I can't seem to display that on the website. I edited the templated page link.html...
What definition file (.def) did you add the field to??? If it is in the category.def file...then you need to replace the following codes in the sub build_category_pages:

Code:

($description, $related, $meta_name, $meta_keywords, $header, $footer) = @{$category{$cat}}[2..7];


with the following codes:

Code:

($description, $related, $meta_name, $meta_keywords, $header, $footer, $file) = @{$category{$cat}}[2..8];


Then in the sub site_html_category routine in the site_html_templates.pl file, add the following tag definition:

Code:

file => $file


Add a , (comma) if it is the last tag definition in the record hash.

Then add the following codes in your category.html file:

Code:

<%if file%>
<%file%>
<%endif%>


Now...if you added the field to the links.def file, then you need to make sure that you updated your existing database with a new column.

Regards,

Eliot Lee

Quote Reply
Re: Adding Fields to 2.0 In reply to
Hello

Success!!!! Thank you all for the help. :)

Ericz