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

Custom Display Based on Links Age

Quote Reply
Custom Display Based on Links Age
Is there anyway to display how old is the link.. i.e. in days.

For example if the Link is new, I am wanting to display certain type of introduction for it, while if the listing is over 30 days old then different format and if the listing is over 90 days, then 3rd format time and so on for upto 365 days.

So was wondering if there was any way to display the age of the link in days?

Thank you.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Custom Display Based on Links Age In reply to
Hi,

You could do it with this global:

do_days_diff
Code:
sub {
my $today = GT::Date::date_get();
my $linkdate = $_[0];
my $diff = GT::Date::date_diff($linkdate,$today);
return { diff => $diff };
}

..then in link.html, use:

Code:
<%do_days_diff($Add_Date)%>
<%if diff <= 30%>
less than 30 days old
<%elsif diff > 30 and diff <= 90%>
between 30 days and 90
<%else%>
older than 90 days
<%endif%>

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] Custom Display Based on Links Age In reply to
It is working partially.

There is only 1 test link in the directory which was added on March 10, 2007. and was modified on April 12, 2007.

Now when I use
Code:
<%do_days_diff($Add_Date)%>
<%if diff <= 4%>
less than 4 days old
<%elsif diff > 4 and diff <= 90%>
between 4 days and 90
<%else%>
older than 90 days
<%endif%>


It displays less than 4 days old, instead of between 4 days and 90 days.

Also if I change the input code to
Code:
<%do_days_diff($Add_Date)%>
<%if diff <= 1%>
less than 1 days old
<%elsif diff > 1 and diff <= 90%>
between 1 day and 90
<%else%>
older than 90 days
<%endif%>

Then it displays less than 1 days old, instead of between 1 day and 90 days.

I tried this on link.html and include_footer.html page, but received same results.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Custom Display Based on Links Age In reply to
Try adding this:

<%diff%>

..right after:

<%do_days_diff($Add_Date)%>

..so we can see the value of "diff" Smile

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] Custom Display Based on Links Age In reply to
I am using below code in include footer page.

Code:
<%do_days_diff($Add_Date)%>
<%diff%>
<%if diff <= 4%>
less than 4 days old
<%elsif diff > 4 and diff <= 90%>
between 4 days and 90
<%else%>
older than 90 days
<%endif%>


& here is the output for it:

-13616 less than 4 days old

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Custom Display Based on Links Age In reply to
Hi,

What if you use:

my $diff = GT::Date::date_diff($today,$linkdate);

?

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] Custom Display Based on Links Age In reply to
hum.. now the output is little different.

Global Used:
Code:
sub {
my $today = GT::Date::date_get();
my $linkdate = $_[0];
my $diff = GT::Date::date_diff($today,$linkdate);
return { diff => $diff };
}


Code in template
Code:
<%do_days_diff($Add_Date)%>
<%diff%>
<%if diff <= 4%>
less than 4 days old
<%elsif diff > 4 and diff <= 90%>
between 4 days and 90
<%else%>
older than 90 days
<%endif%>


----------------------------------
Output
13616 older than 90 days
----------------------------------

----------------------------------
Link Info:
Submitted by: admin
Hits: 0
Added: Mon Mar 12 2007
Last Modified: Sun Apr 08 2007
----------------------------------

It should be showing "between 4 days and 90" as output.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Custom Display Based on Links Age In reply to
Hi,

Mmm.. i think the problem is arising with the format of $Add_Date (i.e its formatted like "March 10th, 2007" , instead of 2007-03-10).

Code:
sub {
my $date = $DB->table('Links')->select( ['Add_Date'], { ID => $_[0] } )->fetchrow;
my $today = GT::Date::date_get();
my $diff = GT::Date::date_diff($date,$today);
return { diff => $diff };
}

..then call with:

<%global_name($ID)%>

Does that do anything different?

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] Custom Display Based on Links Age In reply to
I created a global named linkage2 using above code and called it via <%linkage2($ID)%>. HOwever there is no output, simply shows nothing.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Custom Display Based on Links Age In reply to
Hi,

Mmm.. can you just send me over GLinks access, so I can take a look? Really can't afford any more time trying to debug it over messages :(

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: [SWDevil.Com] Custom Display Based on Links Age In reply to
In Reply To:
I created a global named linkage2 using above code and called it via <%linkage2($ID)%>. HOwever there is no output, simply shows nothing.

Hi,

This definatly works:

Code:
sub {
my $date = $DB->table('Links')->select( ['Add_Date'], { ID => $_[0] } )->fetchrow;
my $today = GT::Date::date_get();
my $diff = GT::Date::date_diff($today,$date);
return { diff => $diff };
}

Called with:

Code:
<%global_name($ID)%>

..then print out <%diff%>

..so:

Code:
<%global_name($ID)%>

Difference in days: <%diff%>

You can see it running here, with a hard-coded ID

http://www.myuksearch.co.uk/.../page.cgi?d=1;p=test

Out of interest, which template are you calling this in? You need to use it ONLY in link.html, or detailed.html (or category.html, inside the <%loop links_loop%> ..<%endloop%> section...)

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] Custom Display Based on Links Age In reply to
I have been doing this testing by adding code in include_footer.html & link.html page.

On my test site & also at http://www.myuksearch.co.uk/.../page.cgi?d=1;p=test I am seeing the output as 13617 what does this number mean?

Input
<%linkage2($ID)%>
Difference in days: <%diff%>

Output
-32

Input
<%do_days_diff($Add_Date)%>
<%diff%>
<%if diff <= 4%>
less than 4 days old
<%elsif diff > 4 and diff <= 90%>
between 4 days and 90
<%else%>
older than 90 days
<%endif%>

Output
13617 older than 90 days

How do I remove the negative sign so I can use it in the above code for custom output based on links age.

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Custom Display Based on Links Age In reply to
Any thoughts on displaying the number of day in positive instead of negative numbers?

Vishal
-------------------------------------------------------