How to "Count" news items

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

How to "Count" news items

Postby bozoka45 » Wed Jan 21, 2004 9:39 pm

Just wanted to show this to anyone who might be interested in doing it. This is the method I used to count the number of items in a profile that will be displayed on the same page. I'm not sure how to do it if they aren't on the same page.

It basically works the same exact way as an <b>ordered list</b>, but you can insert this number anywhere on the page (inside of a table or something). You could also use it to call image's of numbers (instead of using text numbers).

First, within the header tag of the page, add this:

Code: Select all
<script language="JavaScript">
var number=X;
</script>


"x" should be one number less than what you want to start at (If you want to count: 1, 2, 3, 4, 5..., enter "0" for x.

Then, in your style, put this where you want to display the number:

Code: Select all
<script language="JavaScript">
var number=number+X;
document.write(number);
</script>


"X" will be the number it adds by. To go up by one each time, make X "1".

Also, you can add html tags around the word "number."

If you want to call an image file, for example:

Code: Select all
<script language="JavaScript">
var number=number+1;
document.write("http://www.yourwebsite.com/images/"+number+".gif");
</script>


I used this code for numbering on this page:

http://www.otcdraft.com/top100.php
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby Parahead » Thu Jan 22, 2004 7:46 am

bozoka45, I agree that your solution works just fine, but IMHO including Javascript should be avoided as long as possible due to the fact that it doesn´t work on all platforms and can be turned of in the browser. To give some alternative, here is a solution which has the same features that your javascript solution has but works on the serverside with Perl instead.

Place this at the top of your style:
Code: Select all
<PerlCode>
  $countitems{$ProfileName} = X unless(defined($countitems{$ProfileName}));
  $countitems{$ProfileName} = Y + $countitems{$ProfileName};
  $NewsCounter  = $countitems{$ProfileName};
</PerlCode>
X = The number you want to start the count from - Y.
Y = The number you want to increase by for each count.

In the special (buth most common) case where X=0 and Y=1 the code can be simplified to:
Code: Select all
<PerlCode>
  $NewsCounter  = ++$countitems{$ProfileName};
</PerlCode>


Put this in your style where you want to display the number:
Code: Select all
<Field: NewsCounter>
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby bozoka45 » Fri Jan 23, 2004 12:08 am

If I knew Perl, that would have been much easier to figure out. Thanks.
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby InSAnE NiNjA » Fri Jan 23, 2004 11:53 am

there is also the count items addon...
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Postby Parahead » Fri Jan 23, 2004 1:04 pm

InSAnE NiNjA wrote:there is also the count items addon...
NiNjA, you wouldn´t know where to get Sumaleth´s addons, would you? Seems like his site at http://www.sumaleth.com/coranto/ is broken? Maybe it is temporary, or is it me? Sumaleth, don´t know if you are around the forums anymore but please let us know the status of your site if you are... :-)

Anyway, doesn´t the CountItems-addon fetches the *total* number of news in a profile and saves that number to a file, which is not exactly the same thing? But I don´t use it myself so I don´t know if it has this feature as well?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden


Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest

cron