Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Creating New Templates

Quote Reply
Creating New Templates
Hi,

I'm building a news site which is updated daily. There are 8 root categories and no subcategories. The 10 most recent news stories (links) in each category shall appear on a front page. Viewers may click on "More Stories..." in each category to get the older news.

I'm considering the best way to do this is by creating a new template for each category, for example, technology.html, which will display the 10 most recent links, and when viewers click on "More Stories..." it will take them to the standard subdirectory /Technology/ created by the category.html template (I don't mind if the 10 most recent links appear here as well). This way I'll be able to build the front page by using SSI to include the top 10 stories created by the 8 new templates - which shall contain nothing but a tag calling the top 10 links in that category.

If anyone could show me the best way to do this, much obliged.

ruby
Quote Reply
Re: Creating New Templates In reply to
The problem is that the "link" only stores the category number. You have to do a lookup in the category table.

You could also do a "select" on the links database limiting it to all links:

WHERE CategoryID=nn and (isNew=1 or isNew='Yes') LIMIT=10

To do that, you'd need to take the category name, do a reverse look up, get the ID number, and use that on the links database.




Quote Reply
Re: Creating New Templates In reply to
Thanks for the reply. Yes, I've been reading through all the forums relevant to this issue and see the results are inconclusive.
OK, I'll tell you what I did in Links 2.0 to get around this problem, but it's just a temporary measure, looking forward to the results of your research.
So, I set the pages to build only 10 links per page and kept the calls in links.html template down to a skeleton. Then using SSI, I included the 10 category links into a front page. That way I got the 10 newest links in each category to display on the front page. If the viewer wants to read "More Stories..." there is a link which has the search query for the category name. The top 25 links in that category are then displayed. It works quite well - the results can be seen at http://www.newsonjapan.com
I, at least, want to get this function happening in Links SQL. However, when a category name is hit in search.cgi, it displays only the category title and not the links within that category. I haven't been able to work out the code modifications required in search.cgi so that the top 25 links are diplayed when a category name is hit. Would you be able to take a look and give me some ideas on what I should do here?

Looking forward to your response.

Cheers,

ruby
Quote Reply
Re: Creating New Templates In reply to
This is a topic we've been discussing lately. The way Links is set up now, you'd have to add a bunch of subroutines -- or calls to a new build one, to do the building of the 'new' links on a subset of links for a category.

You would write that out to an include file, before you processed the links template, or you could do it with SSI.

I'm not going to get into the details, since I'm working on something similar, and I'm already confused enough as it is!

But, it will take some major hackign to the Links program to do. It was not set up to do more than one "new" page.
Quote Reply
Re: Creating New Templates In reply to
That's right, but what I need is that should a category name be hit, all the links in that category be displayed, the first 25 on the first page, and next pages...
Sorry to ask, but I'm running out of time and my boss is breathing down my neck, but could you show me the code to make this happen? I'm working hard on my Perl by it's not quite there yet.... aagghh ... help!!!
Quote Reply
Re: Creating New Templates In reply to
you've lost me.

Isn't that what the subcategory.html does already?

Quote Reply
Re: Creating New Templates In reply to
Something like:

# Load a links and category database.
my $cdb = new Links: BSQL "$LINKS{admin_root_path}/Category.def";
my $ldb = new Links: BSQL "$LINKS{admin_root_path}/Links.def";

# Go through each category.
my $cats = $cdb->query ({ ID => * });
foreach my $cat (@$cats) {
$cat = $catdb->array_to_hash($cat);
my $id = $cat->{ID};
my $name = $cat->{Name};
# Now get top 10 most recent links for this category.
my $links = $ldb->query ( { CategoryID => $id, sb => 'Add_Date', so => 'DESC', mh => 10 });
foreach my $link (@$links) {
# format them how you'd like and either print them out, or save to file.
}
}

You could either make this a cgi script, or add this to nph-build and have it create an html file.

Hope that helps,

Alex
Quote Reply
Re: Creating New Templates In reply to
Alex...

are you saying pre-generate a list of the top-10 links in each category by number, then each time you winde through each category you just do a looup on that hash for the top-10 in that category?

This is going back to my grandiose idea of pre-generating a whole truckload of stats and variables, perhaps storing them in a "build" table, then being able to use them as variables or pre-generated values.

Whether or not you meant it that way, I can see a routine to generate the top-10 for each category, and maintain that.

For instance, top_10_catID would contain the ID field, and a text field that would hold the value of the top_10_catID data returned from the [link_output .= ] calls.

This only takes up disk space, and once generated, would be available in EVERY template, at any time, with values for that build.

I've been looking at a way to improve efficiency on the top-10 etc stats, for long-term recall, and storing them in a set of tables is the most logical. Expanding this to all the "top 10" type data, would consume relatively little diskspace, require calculating everything only once, then looking up to output the templates.

This would allow fancy searches, and development of extra pages with "top 10" data on them, and not have to search for them each time -- just look them up as a single entry.

Interesting........... ..... .... ... ...





[This message has been edited by pugdog (edited April 17, 2000).]