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

Newest Links with all subcats?

Quote Reply
Newest Links with all subcats?
I just add a new global that takes x newest links and put them to the homepage. Normaly i have news only in ony subcat. But this time i want it like wordpress: An article is in subcat "All" and one or more other subcats like society, politics, sports.

If i select from Links, CatLinks, Category i got a link more than one time; so i should select from Links only.
No problem so far.

But now i want to know all subcats also.

Select * from Links order by Add_Date LIMIT 5
while ...

select from CatLinks, Category where CategorID=ID
while

take name and Path (Path is my variable for the path/url for every cat)
output = title, description and all subcats with link to the right cat

Is this the right way?

Or should i do one select from Links, CatLinks, Category and work with arrays to save all the catnames and (their path) to have what i want?

(Dont care for the path, please. I do it on my own way with two fields path and path2 for language support.)


The result should look like:


I am a title, i am big and fat.
I am a description with max. 255 chars.
added at 12/12/16 and saved in All, Politics and Sports


A click to All, Politics or Sports calls the category page for that category.


Result:

1. Select all needed links and then select the cats

or

2. select all neded links with all cats and save title, description once and all subcats?
Quote Reply
Re: [Robert] Newest Links with all subcats? In reply to
My ULTRAGlobals plugin has something like that:

Code:
<%Plugins::ULTRAGlobals::New_Links_By_Category($ID)%>

<%loop new_links_in_this_cat%>
<%include link.html%>
<%endloop%>

Use that, and then maybe use Get_Image_URL from the same plugin, to get the image URL.

BTW, I did see your PM's - will reply to them tomorrow. I'm off out for a friends birthday now :)

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!
Post deleted by Robert In reply to
Quote Reply
Re: [Andy] Newest Links with all subcats? In reply to
Thank you, Andy,
i tried the code inside my global, but i still would like to know what is better:

1. Take one select from Links, CatLinks, Category
=> LinkID will come as often it is in catlinks.
I open an array for every ID and save my subcats, pass Title, Description and subcats

OR

2. Take my ID one time from Links and all subcats from CatLinks, Category


For shure i want to sort the Name (of Cats) also.
Quote Reply
Re: [Robert] Newest Links with all subcats? In reply to
Before i go on, i would like to know why i always make two selects here:

Code:
my ($output,$bild,@a);
my $tags = shift;

my $all_db = $DB->table('Links');

$all_db->select_options ("ORDER BY Mod_Date DESC", "LIMIT 10");
my $sth = $all_db->select ( ['ID','URL','Title','Description'],
GT::SQL::Condition->new ('isValidated','=','Yes'

) );
while (my ($id,$title,$url,$descr) = $sth->fetchrow_array) {

my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( 'picture', $id );
my $location = $fh->File_RelativePath;
if ($fh->File_Name =~ /\.(jpg|gif)$/) {
$bild="<img src='/$location'>";
}

}


In PHP i would do a leftjoin to fetch everything in one select. Here i am used to fetch first the link then the picture. Is there a reason for this?

Last edited by:

Robert: Sep 4, 2016, 12:57 AM
Quote Reply
Re: [Robert] Newest Links with all subcats? In reply to
I want to play soccer in twenty minutes, so i have not tested the global now

Code:
sub {

my ($output,$bild,$lcats);


my $all_db = $DB->table('Links');

$all_db->select_options ("ORDER BY Mod_Date DESC", "LIMIT 6");
my $sth = $all_db->select ( ['ID','URL','Title','Description','Add_Date'],
GT::SQL::Condition->new ('isValidated','=','Yes'

) );
while (my ($id,$title,$url,$descr,$adate) = $sth->fetchrow_array) {

my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( 'b1', $id );
my $location = $fh->File_RelativePath;
if ($fh->File_Name =~ /\.(jpg|gif)$/) {
$bild="<img src='/aa/b1$location' title=\"$title $id\" alt=\"$title $id\">";
}


$cat_db->select_options ("ORDER BY Name", "");
my $sth = $cat_db->select( ['CategoryID','Name','Pfad'], { LinkID => $id } ) || die $GT::SQL::error;
my @cats;
while (my ($cid,$name,$pfad) = $sth->fetchrow_array) {

$lcats .= "| <a href=\"$pfad\">$name</a> ";
}

get_rid_of_the_first "| " !

$output .= "$bild <br> $title <br>$lcats ";

}
utf8::encode($output);
return $output;
}



It takes the newest ten links for the homepage, fetches a picture and all subcats sorted by name.

The result is eomething like

PICTURE
Title
cat1, cat, ... catn,

Instead of using Full_Name, i use Pfad = Path; (for different languages i have different pathes, but not here in the code)

Last edited by:

Robert: Sep 4, 2016, 12:59 AM
Quote Reply
Re: [Robert] Newest Links with all subcats? In reply to
Hi,

You could do this instead:

Code:
my @cats;
while (my ($cid,$name,$pfad) = $sth->fetchrow_array) {
push @cats, qq~| <a href="$pfad">$name</a> ~;
}

$lcats = join " | ", @cats;

Or if you want to keep you code, you would just remove the first | with something like:

Code:
$lcats =~ s/^\| //;

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!