Gossamer Forum
Home : Products : Links 2.0 : Customization :

Adding Banners Between Listings

Quote Reply
Adding Banners Between Listings
HOw can I put the banners between listings. For instance how can I have 5 listings then a banner. Then another 5 listings show up.

Example:

[url=http://www.undertainment.com/webstats/index.htm]Undertainment Traffic Tracker[/url]
Description
Rate Modify

Banner
[url=http://www.undertainment.com/webstats/index.htm]
[img=http://www.undertainment.com/webstats/images/webstats8.gif][/url]

[url=http://www.undertainment.com/webstats/index.htm]Undertainment Traffic Tracker[/url]
Description
Rate Modify

What would I do to achevice this!

Thanks,[url=http://www.siteproductions.com]
Site Productions Internet Search[/url]
Quote Reply
Re: Adding Banners Between Listings In reply to
You need to go to the build_links routine, and put in a counter, and an if test, such that if 5 links, do this, {insert banner code, reset counter to 1}

It would require some tweaking on the output, to get it to look just right, but that's the idea.

Put your banner code between qq| | and you'll be able to format it more easily in your code.

Look at the end of site_html_templates.pl for an example of that.

Quote Reply
Re: Adding Banners Between Listings In reply to
Hi,

Would anybody have a specific example of this? This would be a nice addition.

Thanks in advance.
Quote Reply
Re: Adding Banners Between Listings In reply to
What file is the build links in?
Quote Reply
Re: Adding Banners Between Listings In reply to
Sorry.. I'm doing things a bit different.

In nph_build.cgi, in the buld_category_pages subroutine, there is a block of code something like (I don't know how modified mine is).

Code:
# If we are spanning pages, we grab the first x number of links and build
# the main index page. We set $numlinks to the remaining links, and we remove
# the links from the list.
$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$next = $prev = $links = "";
if (($numlinks > $build_links_per_page) && $build_span_pages) {
$page_num = 2;
$cat_id = $cat_id.$page_num; ## adds an extension onto the variable for advertising... allows rotation
## see below for pages beyond 2
$next = $url . "more$page_num$build_extension";
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}
@{$links{$cat}} = @{$links{$cat}}[(($#db_cols+1)*$build_links_per_page) .. $#{$links{$cat}}];
$numlinks = ($#{$links{$cat}}+1) / ($#db_cols + 1);
}
# Otherwise we either only have less then x number of links, or we are not
# splitting pages, so let's just build them all.
else {
for ($i = 0; $i < $numlinks; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}
}

This is probably where you'd want to insert banners, as you slice up the links per-page, you can count links, and insert banners.

you can experiment by using a simple print line to see what your output would look like. It will probably take a few tries.

You'd put the advertising counter inside the build_links_per_page block. For some really bad psuedo code:

$banner_countdown = 0
while num_links < links per page
if $banner_countdown < 5 {
insert banner
set $banner_countdown =0
} otherwise {
insert link,
increment $banner_countdown
increment num_links
}


Hope this helps a little.

Someone else might be able to give you the specifics. Unfortunately this something I really can't spend more time with Smile Good luck!
Quote Reply
Re: Adding Banners Between Listings In reply to
The way I would handle this is go into nph-build.cgi, sub build_category_pages. You will see various occurances of the following code:

Code:
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);

That code is what builds the links being displayed on the category pages. Change each occurance to read:

Code:
$link_count = 0;
for ($i = 0; $i < $build_links_per_page; $i++) {
$link_count++;
if ($link_count > 5) {
$link_count = 0;
$links .= qq~<a href="http://www.undertainment.com/webstats/index.htm">
<img src="http://www.undertainment.com/webstats/images/webstats8.gif"></a>
<p>~;
}
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);

This may need tweeking. I have not tested it but it should work.

I hope this helps.
Quote Reply
Re: Adding Banners Between Listings In reply to
Thanks for the code, Bobsie.

I plugged it in. Here's what I got:

1. It inserted the ad only if I had more than one full page in a particular category.

If I didn't have more than one full page in that category, no banner showed up.

2. On the last page of the category, if I had more than one full page but I didn't have a full last page, the last page was filled out with

-(Added: Hits: Rating: Votes: ID: )Rate It

Take a look on one of my pages:
www.armynavy.com/pages2/Military_Surplus/more13.shtml

Feel free to look around to see how it came out.

The link for the banner worked fine.

Any ideas for (1) adding a banner in a category that has not got more than one full page and (2) eliminating those extra (Added: Hits: ....) outputs?

Many thanks in advance.



[This message has been edited by TrainedMonkey (edited August 08, 1999).]
Quote Reply
Re: Adding Banners Between Listings In reply to
Trained Monkey,

Like that name. I think it has to do with your templates (I think you are using templates). You might want to try using <%if%> <%endif%> to display a ratings only when there is a link and might solve your problem.

<%if links%>
<%links%>
then your code for rate this link
<%endif%>

Please let us know if it worked.
Quote Reply
Re: Adding Banners Between Listings In reply to
How many times did you plug it in for that subroutine. There are two places based on the original code I posted and one more that is slightly different:

Code:
LINK: for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
last LINK if ($tmp{$db_key} eq "");
$links .= &site_html_link (%tmp);

The code would go after the "last LINK" line.

I hope this helps.
Quote Reply
Re: Adding Banners Between Listings In reply to
Bobsie,

I looked all over the place, but all I could find were two occurences, total, in sub build_category_pages of:

for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);


The first one, I just cut and pasted the code:

$link_count = 0;
for ($i = 0; $i < $build_links_per_page; $i++) {
$link_count++;
if ($link_count > 5) {
$link_count = 0;
$links .= qq~<a href="http://www.undertainment.com/webstats/index.htm">
<img src="http://www.undertainment.com/webstats/images/webstats8.gif"></a>
<p>~;
}
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);



The second one, the first time I did it, I went from this:

LINK: for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
last LINK if ($tmp{$db_key} eq "");
$links .= &site_html_link (%tmp);



to this:

LINK: $link_count = 0;
for ($i = 0; $i < $build_links_per_page; $i++) {
$link_count++;
if ($link_count > 5) {
$link_count = 0;
$links .= qq~<a href="http://www.undertainment.com/webstats/index.htm">
<img src="http://www.undertainment.com/webstats/images/webstats8.gif"></a>
<p>~;
}
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);

This is where I got the extra (Added: Hits: ...) and no banner in categories that didn't have more than one full page.



The second time (after reading your most recent post), the first piece of code was the same, but the second piece was added after "last LINK" and went like this:

LINK: for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
last LINK if ($tmp{$db_key} eq "");
$link_count = 0;
for ($i = 0; $i < $build_links_per_page; $i++) {
$link_count++;
if ($link_count > 5) {
$link_count = 0;
$links .= qq~<a href="http://www.undertainment.com/webstats/index.htm">
<img src="http://www.undertainment.com/webstats/images/webstats8.gif"></a>
<p>~;
}
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);


Also, for this second time, when I tried to rebuild the pages, I got an error message - "page cannot be displayed" (I believe that this is a 404).

I tried a few times to rebuild, but I kept getting the error. So, I went back to my backup nph-build and tried it again just to make sure it wasn't some external problem, and the pages built fine (without the banners, of course).

If you would like me to post my entire sub build_category_pages code, let me know. I use Span Pages, which makes this part of nph-build about 200 lines, but it seems that the relevant sections are unaffected by Span Pages.

Many thanks for your help.



[This message has been edited by TrainedMonkey (edited August 09, 1999).]
Quote Reply
Re: Adding Banners Between Listings In reply to
Thanks, Socrates, for your suggestion. I'm gonna wait to hear from Bobsie about his code before I try combinations of things. I've learned to tweak one thing at a time to see what happens.

Many thanks.
Quote Reply
Re: Adding Banners Between Listings In reply to
Socrates,

I'm looking into your suggestion. Are you saying that I should add the rating code to my category.html page? If so, where do I get that code, and how exactly should I add it?

This will be a new one for me.

Many thanks.
Quote Reply
Re: Adding Banners Between Listings In reply to
Anybody got any ideers?

Thanks.

------------------
http://www.armynavy.com/
Quote Reply
Re: Adding Banners Between Listings In reply to
If anyone has any ideas about tweaking this, I'd love to hear 'em.

"This'll be my last transmission, Houston."

Many thanks in advance.

------------------
www.armynavy.com/


[This message has been edited by TrainedMonkey (edited August 17, 1999).]
Quote Reply
Re: Adding Banners Between Listings In reply to
There are two occurances of:

Code:
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);

That should be changed to:

Code:
$link_count = 0;
for ($i = 0; $i < $build_links_per_page; $i++) {
$link_count++;
if ($link_count > 5) {
$link_count = 0;
$links .= qq~<a href="http://www.undertainment.com/webstats/index.htm">
<img src="http://www.undertainment.com/webstats/images/webstats8.gif"></a>
<p>~;
}
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);

There is also one occurance of:

Code:
LINK: for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
last LINK if ($tmp{$db_key} eq "");
$links .= &site_html_link (%tmp);

As I said previously, the new code would go after the line that begins with last LINK if

I hope this helps.
Quote Reply
Re: Adding Banners Between Listings In reply to
Hi, Bobsie,

I looked again, but all I could find were one of each.

So, what I did was post my nph-build/sub build_category_pages for you to look at if you get a chance.

Under www.armynavy.com/bobsie1.html , I've posted the original Links code.

Under www.armynavy.com/bobsie2.html , I've posted my current code that includes some modifications.

I've marked where I found the code. Look for HERE along the left side.

In each file, I could find only 1 instance of

for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);



I did find the other code with no trouble.

LINK: for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
last LINK if ($tmp{$db_key} eq "");
$links .= &site_html_link (%tmp);


If you could take a look and give me your thoughts, I'd be most grateful.

Many thanks.









------------------
www.armynavy.com/



[This message has been edited by TrainedMonkey (edited August 25, 1999).]

[This message has been edited by TrainedMonkey (edited August 25, 1999).]
Quote Reply
Re: Adding Banners Between Listings In reply to
Sorry, my error. While the first one is in there twice as I said, it uses a different variable (I didn't notice that). Look at this code and you will see two "for loops" that need editing:

Code:
# If we are spanning pages, we grab the first x number of links and build
# the main index page. We set $numlinks to the remaining links, and we remove
# the links from the list.
$numlinks = ($#{$links{$cat}} + 1) / ($#db_cols + 1);
$next = $prev = $links = "";
if (($numlinks > $build_links_per_page) && $build_span_pages) {
$page_num = 2;
$next = $url . "more$page_num$build_extension";
for ($i = 0; $i < $build_links_per_page; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}

@{$links{$cat}} = @{$links{$cat}}[(($#db_cols+1)*$build_links_per_page) .. $#{$links{$cat}}];
$numlinks = ($#{$links{$cat}}+1) / ($#db_cols + 1);
}
# Otherwise we either only have less then x number of links, or we are not
# splitting pages, so let's just build them all.
else {
for ($i = 0; $i < $numlinks; $i++) {
%tmp = &array_to_hash ($i, @{$links{$cat}});
$links .= &site_html_link (%tmp);
}

}

I hope this helps.

[This message has been edited by Bobsie (edited August 26, 1999).]
Quote Reply
Re: Adding Banners Between Listings In reply to
Many thanks, Bobsie. I'll give this a shot.

------------------
www.armynavy.com/

Quote Reply
Re: Adding Banners Between Listings In reply to
Hi, Bobsie,

I plugged in the new code as best as I could, and I tried to Build the pages several times, but I still get an error message - "The page cannot be displayed."

So, I updated http://www.armynavy.com/bobsie2.html to show the newly modified nph-build sub build_category_pages code.

I think I did it the way that you had intended, but if you could take a look, I'd be very grateful.

Thanks.

------------------
www.armynavy.com/

Quote Reply
Re: Adding Banners Between Listings In reply to
TrainedMonkey,

The section of your code, marked with the final <HERE> is missing a right bracket at the end. Try adding another } as follows:

Quote:
for ($i = 0; $i < $build_links_per_page; $i++) {
$link_count++;
if ($link_count > 5) {
$link_count = 0;
$links .= qq~<a href="http://www.undertainment.com/webstats/index.htm">
<img src="http://www.undertainment.com/webstats/images/webstats8.gif"></a>
<p>~;
}
}

I hope this helps.
Quote Reply
Re: Adding Banners Between Listings In reply to
Great!

Now the pages are building.

However, the last page in each category is what needs some work.

For example, take a look at www.armynavy.com/pages2/Y2K/ . The first page looks good, but then go to the last page in this category. See what happens? There are no links on the page even though there should be 9 of them, and (Added: Hits: Rating: Votes: ID: )Rate It is showing up without a link to go with it.

Any thoughts?

I appreciate your help.

------------------
www.armynavy.com/



[This message has been edited by TrainedMonkey (edited August 29, 1999).]
Quote Reply
Re: Adding Banners Between Listings In reply to
According to your home page, there are 14 links in that Y2K category. Ten of them show on the first page. I do not know what is happening to the last 4 but I do know that you have an awful lot of extra coding in your script to handle multiple pages. Perhaps something in that is messing up. I would suggest that you start fresh with just the mods for that banner after every 5 links, and then try to bring in the multi-page mods you have made. See if you can spot anything haywire.

I'm not much help, I am afraid.
Quote Reply
Re: Adding Banners Between Listings In reply to
Thanks, Bobsie. The extra coding is there from the Span Pages Mod updates. Actually, the Span Pages mod works very well now since it's been updated, despite it's low rating at the Resource Center.

I'll look around and see what I can do. If I fix it, I'll post it here.

Thanks for your help. I appreciate it.

------------------
www.armynavy.com/