Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Modified links with Category names

(Page 1 of 2)
> >
Quote Reply
Modified links with Category names
I am using this global that lists the latest modified links of me but I want to be able to have the category listed with each link, say Link 5 was modified today, and was in category1 i want to be able to have

Link1, Category1
Link2, Category2
Link3, Catgeory3 and ..........



sub {
my $tags = shift;
my $table = $DB->table('Links');
$table->select_options ('ORDER BY Mod_Date DESC', 'LIMIT 30');
my $sth = $table->select; my @output; while (my $link = $sth->fetchrow_hashref) {
push (@output, $link); }
return { modlinks => \@output }; }
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
Try this;

Code:
sub {
my $id = $_[0];
my $table = $DB->table('Links');
my $tablecat = $DB->table('Category');
$tablecat->select_options('LIMIT 1');
my $tablecatlinks = $DB->table('CatLinks');
$table->select_options ('ORDER BY Mod_Date DESC', 'LIMIT 30');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
my $cat_id = $tablecatlinks->select(['CategoryID'],{ LinkID => $id })->fetchrow;
$link->{Category} = $tablecat->select(['Full_Name'],{ ID => $cat_id })->fetchrow;
push (@output, $link);
}


return { modlinks => \@output };

}

That should work.

<%global_name($ID)%> ... where <%ID%> is the link ID number.

When using the loop, you should now have <%Category%> tag available to you.

Night :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Modified links with Category names In reply to
When I used this
<%global_name($ID)%>

I got this error

Error: Variable 'modlinks' is not a code referenc

Where my global name I used wass (modlinks)




I already have a loop which I am calling in my template

<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%" target="_blank"><%Title%></a>

I need it like this

Category Name : <a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>" target="_blank"><%Title%></a>

Last edited by:

Abusaki: Sep 3, 2004, 11:57 AM
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
You using it on the right page? The code looks fine to me (nothing obvious I can see, unless you give me an error message that its producing).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Modified links with Category names In reply to
Isn't it category_id instead of categoryid?

Also I found it easier to say:
Code:
<%global_name%>


my $in = shift;
my $id = $in->{ID};

which automatically grabs any ID for input instead of saying

Code:
<%global_name($ID)%>
my ID = $_[0];


the mantle is on fire,

- Jonathan

Last edited by:

jdgamble: Sep 4, 2004, 2:19 AM
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Quote:
Also I found it easier to say:

I made a post not so long ago, discussing this before =) We came to the conclusion its just a matter of preferences, and it doesn't really have a speed effect.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Modified links with Category names In reply to
It just seems to easier to me to say <%global_name%> everytime you need it than having to import ID everytime.

Anyway, if you want to use templates you could do something like this:

Code:

sub {
#---------------------------------------------------
# Display the latest modified
my ($sth,$tab,$output);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY MOD_DATE Desc', 'LIMIT 30');
$sth = $tab->select( { isValidated => 'Yes' } );
while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link_modified', $rec);
}
return $output;
}


However, the category will not be displayed in the link_modified.html template, so you could create a category tag to be displayed like so:

Code:

'category' => 'sub {
my $tag = shift;
my ($table, $sth, $catID, $cattable, $sth2, $name, @dirs, $output);
$table = $DB->table (\'CatLinks\');
$sth = $table->select ( { LinkID => $tag->{ID} }, [\'CategoryID\'] );
$catID = $sth->fetchrow();
$cattable = $DB->table(\'Category\');
$sth2 = $cattable->select ( { ID => $catID }, [\'Full_Name\'] );
$name = $sth2->fetchrow_array;
@dirs = split (/\//, $name);
$output = "<a href=\"$CFG->{\'build_root_url\'}/$CFG->{\'build_index\'}\">Home</a>&nbsp&gt";
for (0 .. $#dirs) {
my $path = "/" . $cattable->as_url( join "/", @dirs[0 .. $_] );
$output .= " <a href=\"$CFG->{\'build_root_url\'}$path/$CFG->{\'build_index\'}\">$dirs[$_]</a>&nbsp&gt";
}
return $output;


Although this might be a lot more complicated, it is more customizable. I want to create a template for the category (title_linked)... I will do it when I get the time. If you don't like the way this looks, there are other category sub routines written throughout this forum.

LSU needs to start playing,

- Jonathan

Last edited by:

jdgamble: Sep 4, 2004, 5:23 PM
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Quote:
It just seems to easier to me to say <%global_name%> everytime you need it than having to import ID everytime.

I'm not even gonna try to argue Tongue Its just a case of personal preference.

For example, some people do this when passsing variables in;

<%global_name("var1","var2","var3")%>

Code:
my $var1 = $_[0];
my $var2 = $_[1];
my $var3 = $_[2];

... whilst others do;

Code:
my ($var1,$var2,$var3) = @_;

...or;

Code:
my ($var1,$var2,$var3) = shift;

...or even;

Code:
my @vars = shift;

When I first started coding like that, I thought that it was a little faster (as you are only passing in one string, instead of importing the whole hash into the global). However, I'm not sure this is the case now. I just prefer to code that way =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Modified links with Category names In reply to
   
It is a matter of personal preference, your way sucks!

Just kidding.

I actually use your way when I import something that might change with the page.

see <li> links.html template for example...

Wink

It all depends upon the person and situation!

Now that I think about it, it probably is a bit faster.

Shift imports all parameters into an array, while _[0] or @_ imports just the ones you want.

Then again, since I do not understand the core workings of perl, _[0] and the shift array might be created no matter what (rather or not perl calls them).

Either way, if it is one thousanth of a second faster, I don't care.

- Jonathan
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Quote:
Either way, if it is one thousanth of a second faster, I don't care.

Ditto :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Modified links with Category names In reply to
Thank you both for your help, but I still do not get how to fix this problem.

I have this on my home.html template


<%modlinks%>
<%loop modlinks%>

<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%" target="_blank"><%Title%></a>

<%endloop%>


Now I do not know where to put the
<%global_name($ID)%> ... where <%ID%> is the link ID number.
sso I can get the category listed,

I would love to link the category as well

I would like it to look like this


<%modlinks%>
<%loop modlinks%>

<%XXXXXXXXX%> <a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%" target="_blank"><%Title%></a>

<%endloop%>



Where <%XXXXXXXXX%> will give me <a href="http:www.domain.com/category.html>Category</a>


SO for my modified links I have this showing on my homepage

<a href="http:www.domain.com/category.html>Category</a>: <a href="http:www.domain.com/cgi-bin/jump.cgi?ID=alinkID>Title</a>




i tried this


<%modlinks($ID)%>
<%loop modlinks%>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%" target="_blank"><%Title%></a>
<%endloop%>


as well as


<%modlinks%>
<%loop modlinks%>
<%modlinks($ID)%> <a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%" target="_blank"><%Title%></a>
<%endloop%>

but none worked
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
This is what you want:

Code:
'last_modified' => 'sub {my ($sth,$tab,$output,$tabcat, $cat_id, $category,%rec,$rec, $sthcat);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY MOD_DATE Desc', 'LIMIT 5');
$tabcat = $DB->table('CatLinks');
$category = $DB->table('Category');
$sth = $tab->select( { isValidated => 'Yes' } );
while ($rec = $sth->fetchrow_hashref) {
$cat_id = $tabcat->select(['CategoryID'],{ LinkID => $rec->{ID} })->fetchrow;
$sthcat = $category->select(['Full_Name'],{ ID => $cat_id })->fetchrow;
$rec->{category} = $sthcat;
$rec->{category_url} = $category->as_url($sthcat);
$output .= Links::SiteHTML::display('link_home', $rec);}}',


Now you must create a template called link_home.html

In you template you can put this:

<a href="<%build_root_url%>/<%category_url%>"><%category%></a> (for your category)
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a> (for your link)

In home.html you can call the global by saying <%last_modified%> (you don't need any input)

Hope this works for you,

- Jonathan

Last edited by:

jdgamble: Sep 8, 2004, 4:30 PM
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Thanks Jonathan,
I did exactly what you said but when I call the gobal <%last_modified%> in the home.html


I get this instead on my homepage

'last_modified' => 'sub {my ($sth,$tab,$output,$tabcat, $cat_id, $category,%rec,$rec, $sthcat); $tab = $DB->table('Links'); $tab->select_options('ORDER BY MOD_DATE Desc', 'LIMIT 5'); $tabcat = $DB->table('CatLinks'); $category = $DB->table('Category'); $sth = $tab->select( { isValidated => 'Yes' } ); while ($rec = $sth->fetchrow_hashref) { $cat_id = $tabcat->select(['CategoryID'],{ LinkID => $rec->{ID} })->fetchrow; $sthcat = $category->select(['Full_Name'],{ ID => $cat_id })->fetchrow; $rec->{category} = $sthcat; $rec->{category_url} = $category->as_url($sthcat); $output .= Links::SiteHTML::display('link_home', $rec);}}',
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
So its printing the code instead of executing it? How did you install the code. Did you copy it inside your globals.txt? Try going to your linksSQL Admin, go under build-template globals... create a new global called last_modified and copy the code into there (everything except sub{ and }', ). That does the same thing as copying the code directly to globals.txt. If the code gets changed (you'll know when you see a lot of % signs), try copying it to wordpad or notepad first, then copy it to the globals.

Good luck,

- Jonathan
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Hi Jonathan,

it is still printing the code instead of executing it

my ($sth,$tab,$output,$tabcat, $cat_id, $category,%rec,$rec, $sthcat); $tab = $DB->table('Links'); $tab->select_options('ORDER BY MOD_DATE Desc', 'LIMIT 5'); $tabcat = $DB->table('CatLinks'); $category = $DB->table('Category'); $sth = $tab->select( { isValidated => 'Yes' } ); while ($rec = $sth->fetchrow_hashref) { $cat_id = $tabcat->select(['CategoryID'],{ LinkID => $rec->{ID} })->fetchrow; $sthcat = $category->select(['Full_Name'],{ ID => $cat_id })->fetchrow; $rec->{category} = $sthcat; $rec->{category_url} = $category->as_url($sthcat); $output .= Links::SiteHTML::display('link_home', $rec);}
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
Try copying the code again.. here:

Code:

my ($sth,$tab,$output,$tabcat, $cat_id, $category,%rec,$rec, $sthcat);
$tab = $DB->table('Links');
$tab->select_options('ORDER BY MOD_DATE Desc', 'LIMIT 5');
$tabcat = $DB->table('CatLinks');
$category = $DB->table('Category');
$sth = $tab->select( { isValidated => 'Yes' } );
while ($rec = $sth->fetchrow_hashref) {
$cat_id = $tabcat->select(['CategoryID'],{ LinkID => $rec->{ID} })->fetchrow;
$sthcat = $category->select(['Full_Name'],{ ID => $cat_id })->fetchrow;
$rec->{category} = $sthcat;
$rec->{category_url} = $category->as_url($sthcat);
$output .= Links::SiteHTML::display('link_home', $rec);
}


Use the linksSQL-build-template globals this time creating the last modified part... If you still have problems, email me your globals.txt file...

webmaster@magicdirectory.com

- Jonathan
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Hi Jonathan,
It is still priing the code so I sent you a private message
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
You need to put that code in a sub { } i.e;

Code:
sub {

... current code you have

}

...otherwise LinksSQL won't know that you want to execute the routine Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Modified links with Category names In reply to
Still not working,

What if I am still using this gobal with name modlinks

sub {
my $id = $_[0];
my $table = $DB->table('Links');
my $tablecat = $DB->table('Category');
$tablecat->select_options('LIMIT 1');
my $tablecatlinks = $DB->table('CatLinks');
$table->select_options ('ORDER BY Mod_Date DESC', 'LIMIT 30');
my $sth = $table->select;
my @output;
while (my $link = $sth->fetchrow_hashref) {
my $cat_id = $tablecatlinks->select(['CategoryID'],{ LinkID => $id })->fetchrow;
$link->{Category} = $tablecat->select(['Full_Name'],{ ID => $cat_id })->fetchrow;
push (@output, $link);
}


return { modlinks => \@output };

}


and in my home.html I am calling the global byusing a loop



<%modlinks%>
<%loop modlinks%>
<a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>&afsrc=1" target="_blank"><%Title%></a>
<%endloop%>

What I need to know now is since I use <%Title%> for Title what do I use for the category name for that particular

can i use

<%modlinks%>
<%loop modlinks%>
<%cat_id%>: <a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>&afsrc=1" target="_blank"><%Title%></a>
<%endloop%>

Is this a valid tag
<%cat_id%>
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
I don't understand. When you sent me your global.txt file you did not have the global copied in there at all.

Quote:

What if I am still using this gobal with name modlinks


You can name it whatever you want, just make sure you keep the global the same when you call it.

Quote:

What I need to know now is since I use <%Title%> for Title what do I use for the category name for that particular

can i use


You shouldn't have to do a loop at all. That is why I set it up to use a link_home.html template. I tested the code so I know it works. No <%cat_id%> will not work because you have not declared it anything.

What you need to do is use the global I sent you, call it with <%last_modified%> (or you can rename the sub routine mod_links and call it with <%modlinks%>), create a link_home.html template like I said, and you can use <%category%> and <%category_url%> as your code inside the link_home.html template.

Do you not understand how to install it at all?

- Jonathan
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Sorry Jonathan,
looks like I sent you the globals.txt from default instead of default/local/

Well I got the global in and it is not printing the code but gives me no results

I pm'ed you
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
Sorry for taking so long to reply. Your global file looks fine. Are you calling it the right way?

It should be called by <%modlinks%> in your home.html file.

You should also create and edit a new link file called link_home.html to edit the way you want your modifed links to look (refer to my previous post for more info on this).

Tell me EXACTLY what errors you are getting, and use the EXACT method I have above to call the function.

Once again, good luck!

- Jonathan
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
hi Jonathan, Thanks for the reply.
I am using the exact steps, I have the link_home.html which contains

<table><tr><td><a href="<%build_root_url%>/<%category_url%>"><%category%></a></td>
<td><a href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a></td></tr></table>

But when I call the global in the home.html I just get a blank space,
nothing prints

When I view source for the home page nothing appears where it is supposed to
Quote Reply
Re: [Abusaki] Modified links with Category names In reply to
I think I found the problem...

I did not post the return at all... go to build --> template globals

click the check next to modlinks and delete that global (to avoid confusion)

Edit the global for last_modified and add this line to the end of the global before the last }
Code:

return $output;


Just needs a little return. Make sure you call it in home by using <%last_modified%> instead of <%modlinks%>. You can rename the global to modlinks either way.

Sorry for not making this clear. I should have posted the entire sub routine. Usually its the small things that confuse us,

- Jonathan
Quote Reply
Re: [jdgamble] Modified links with Category names In reply to
Thanks Jonathan,
it is still not printing out anything
> >