Gossamer Forum
Home : Products : Links 2.0 : Customization :

No Categories Found after a search

Quote Reply
No Categories Found after a search
On some searches at my site there are sometimes no matching categories so all that shows up is

Categories:

Can someone please tell me how I can alter the code so that if there are no category hits, a html message is displayed such as...

Sorry No Matching Category Hits

The section of code in search.cgi I thought needs to be changed is this:


# Build the HTML for the category results and store it in "$category_results". Only build the html
# if we are on the first set of link results.
foreach $category (@category_results) { $cat_hits++; }
$half = $cat_hits / 2;
if ($nh == 1) {
$category_results = qq|<table bgcolor="#ffffff" align="left" border="0" cellpadding="0" cellspacing="0" width="100%">\n<tr>\n<td width="50%">\n|;
foreach $category (@category_results) {
if ($cat_count == $half) {
$category_results .= qq|</td>\n<td width="50%">|;
}
$cat_clean = &build_clean($category);
$linked_title = &build_linked_title ($category);
$category_results .= qq|<li>$linked_title\n|;
$cat_count++;
}
$category_results .= qq|</td>\n</tr>\n</table>|;
}

$cat_hits ||= 0;
$lowrange = ($nh-1) * $maxhits + 1;
$highrange = $nh * $maxhits;



From Paul Wilson.
http://www.audio-grabber.com
Music Directory
Quote Reply
Re: No Categories Found after a search In reply to
Quote Reply
Re: No Categories Found after a search In reply to
Just use if statements in your template.
Code:
<%if category_results%>
<h2>Categories:</h2>
<ul><%category_results%></ul>
<%endif%>
BTW, that code is in the original search_results.html template.

--Drew
Quote Reply
Re: No Categories Found after a search In reply to
I use site_html.pl

I think everyone is getting confused.

I am not saying that I want to change this bit...

Your search returned 5 categories and 5 links

I want to change the actual category listings that show up on results pages.
At the top you get a list of matching categories..eg

Categories:
Main > Sub1 > Sub1
Next > Sub2 > Sub2

Links:
BLA BLA BLA

What I want is to display an error message if there are no matching categories!

Hope you understand!

From Paul Wilson.
http://www.audio-grabber.com
Music Directory
Quote Reply
Re: No Categories Found after a search In reply to
Code:

if ($category_results) {
qq~Categories: $category_results~;
}
else {
qq~No Categories~;
}


As an installer, you should be able to translate between tags in templates to variables/codes in the subroutines in the site_html.pl file.

Wink

Regards,

Eliot Lee

Quote Reply
Re: No Categories Found after a search In reply to
I do, I just got this one slightly wrong!

I tried to use similar code to the code you have just provided me with, exept I tried to write it so that if category results were 0, then an error would show.

I obviously got the code slightly wrong!

Sorry!

From Paul Wilson.
http://www.audio-grabber.com
Music Directory