Help Sorting News by Date & Tables

Is Coranto not working properly for you? Here's where to ask for support help; for best results, follow these steps:
  • - Check your core/addon documentation for possible solutions
  • - Search these forums for similar problems that have already been solved
  • - If you're still stumped, check out THIS TOPIC, and post your question in this forum!!

Moderators: Spunkmeyer, Dale Ray, SrNupsen, Bluetooth, Jackanape

Help Sorting News by Date & Tables

Postby MrCodeDude » Sun Dec 21, 2003 2:02 am

Link to site: http://www.mrcodedude.com/sneek/

See how all the dates and posts all go in the same table? I would like it to look like this: Image

The current code I'm using is:

Code: Select all
<If: Sub: isNewDate>
   <span class="date">» <Field: Date></span><br>
   <img src="http://www.mrcodedude.com/sneek/media/hr.gif" height="15" width="570"><Br></If>

<div style="border-bottom:1px dashed #000000;">
<span class="headline"><Field: Subject></span><font size="1">posted by: <b><a href="mailto:<Field: UserField_Email>" class="bot"><Field: User></a></b> @ <Field: Hour>:<Field: Minute><Field: AMPM></font><br></div><div style="margin-left:15px; margin-right:15px;" align="left"><span style="font-size: 6pt"><br></span><font size="2"><Field: Text></font></div><div align="right"><font size="1">comments | forums</font></div><br>


How do I make it so that if there is a post on a new day, it creates a new table? So it would look like it does in the picture?
MrCodeDude
 
Posts: 20
Joined: Tue Apr 02, 2002 2:58 am

Postby Dale Ray » Sun Dec 21, 2003 8:51 am

Formatting like this has been discussed before and the problem is that your style does not know if it is the first, second or last pass. You could include a custom field that is a radio button with the values start, end, none (make the default none) and then:


Code: Select all
<If: Sub: isNewDate>
    <If: Field: CustomField_StartEnd eq "start">
        <table border="0" width="570" cellpadding="7"><tr><td>
    <If: Else>
         </td></tr></table>
         <table border="0" width="570" cellpadding="7"><tr><td>
    </If>
   <span class="date"> <Field: Date></span><br>
   <img src="http://www.mrcodedude.com/sneek/media/hr.gif" height="15" width="570"><Br>
</If>

<div style="border-bottom:1px dashed #000000;">
<span class="headline"><Field: Subject></span>
<font size="1">posted by: <b><a href="mailto:<Field: UserField_Email>" class="bot">
<Field: User></a></b> @ <Field: Hour>:<Field: Minute><Field: AMPM></font><br></div>

<div style="margin-left:15px; margin-right:15px;" align="left"><span style="font-size: 6pt"><br></span>
<font size="2"><Field: Text></font></div><div align="right"><font size="1">comments | forums</font></div>
<br>

<If: Field: CustomField_StartEnd eq "end">
    </td></tr></table>
</If>


OK, this checks for a new date and if it is a new date AND it is the first item it opens your table, row, and cell.

If it is a new date and NOT the first item, it closes the cell, row, and table and opens a new table, row, and cell.

The last if closes the cell, row, and table when the lst item has been processed.

To use this you have to mark the first and last items to be displayed, so when you add a new item you will have to edit the last item you added to change the value of the custom field. The oldest item will be determined by how your filtering is set up on that profile, if it includes all items you will have to mark the last (oldest?) ne as the end. If you are filtering by X number of items you will have to mark X item as the end.

If you are using SSI or PHP to include your news and WANT an empty table in this spot if there is no news to display you can elminate the first test in the the IF Else statement and put your OPENING table tag in your page, then the style will close the last table after the last item.

The extra field will only have effect in styles that evaluate it, so other profiles using the same news items won't be effected by it.

NOTE: Style code not tested. Also, the code gurus here may be able to do this in a more elegant manner.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby LoneOwl » Sun Dec 21, 2003 9:59 am

In your style...
Code: Select all
<If: Sub: isNewDate>
<PerlCode>
if (not $RandomVariableThatShouldNotExistElsewhere) {
</PerlCode>
The bottom of your table goes here.
<PerlCode>
}
$RandomVariableThatShouldNotExistElsewhere++;
</PerlCode>
The top of your table goes here.
</If>
Post stuff goes here.

And after the include on the page.
Code: Select all
The bottom of your table.
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Dale Ray » Sun Dec 21, 2003 5:04 pm

LoneOwl,

In your example where in the style are you placing the code?

If it is at the top you will close an empty table then open another when the first item is processed.

Also, this doesn't solve the problem of having unwanted html markup if there are no items to display.

Code: Select all
<table>
SSI Include for news here
</table>


If there are no items to display, then you have an empty table, or list, or div, or whatever container messing up you markup and possibly your formatting.

Does the variable you are using persist from pass to pass thru the style. In other words, it is set to 1 when the first item is processed, when the second item is processed is it still one? If it persists, then you will never close the table.

If it doesn't persist, what does this code do that isn't done by the IsNewDate sub?

Also, let's say the profile represents a section of the page and you want to print the section header ONLY if there are items to display, this won't fix that.

Here is the logic? I am looking for:

Code: Select all
If it is the first item and a new day print header and open container
If it is a new day, but not the first close the container and open a new one

print all other items for that day in container

after the last item close the container


I know that the isNew(Day, Week, Month) subs could do this if you could detect the first and last items being processed. It would be nice to have the functionality for other forms of sorting also.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby LoneOwl » Sun Dec 21, 2003 10:01 pm

Dale Ray wrote:LoneOwl,

In your example where in the style are you placing the code?
It could be the entire style if you wish. "Post stuff goes here" is the non isNewDate stuff.

Dale Ray wrote:If it is at the top you will close an empty table then open another when the first item is processed.
The PerlCode prevent that.

Dale Ray wrote:Also, this doesn't solve the problem of having unwanted html markup if there are no items to display.
So all you have to do is make sure there's always something.

Dale Ray wrote:
Code: Select all
<table>
SSI Include for news here
</table>


If there are no items to display, then you have an empty table, or list, or div, or whatever container messing up you markup and possibly your formatting.
Can't win them all?

Dale Ray wrote:Does the variable you are using persist from pass to pass thru the style. In other words, it is set to 1 when the first item is processed, when the second item is processed is it still one? If it persists, then you will never close the table.
It's a global variable that will last until Coranto exits.

Dale Ray wrote:If it doesn't persist, what does this code do that isn't done by the IsNewDate sub?

Also, let's say the profile represents a section of the page and you want to print the section header ONLY if there are items to display, this won't fix that.
Coranto isn't designed to handle that.

Dale Ray wrote:Here is the logic? I am looking for:

Code: Select all
If it is the first item and a new day print header and open container
If it is a new day, but not the first close the container and open a new one

print all other items for that day in container

after the last item close the container


I know that the isNew(Day, Week, Month) subs could do this if you could detect the first and last items being processed. It would be nice to have the functionality for other forms of sorting also.
If you know how many items you will have in the profile, this is possible. It's even possible for multiple profiles to have different numbers and all use the same style. If you filter by date, well you could always write a small script that would parse an input file and show it just how you want.
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby MrCodeDude » Mon Dec 22, 2003 2:49 am

I tried both methods, neither seemed to work.

Using LoneOwl's method, my code looked like this:

Code: Select all
<If: Sub: isNewDate>
<PerlCode>
if (not $RandomVariableThatShouldNotExistElsewhere) {
</PerlCode>
</td></tr></table>
<PerlCode>
}
$RandomVariableThatShouldNotExistElsewhere++;
</PerlCode>
<table border="0" width="570" cellpadding="7"><tr><td>
</If>
<If: Sub: isNewDate>
   <span class="date">» <Field: Date></span><br>
   <img src="http://www.mrcodedude.com/sneek/media/hr.gif" height="15" width="570"><Br></If>

<div style="border-bottom:1px dashed #000000;">
<span class="headline"><Field: Subject></span><font size="1">posted by: <b><a href="mailto:<Field: UserField_Email>" class="bot"><Field: User></a></b> @ <Field: Hour>:<Field: Minute><Field: AMPM></font><br></div><div style="margin-left:15px; margin-right:15px;" align="left"><span style="font-size: 6pt"><br></span><font size="2"><Field: Text></font></div><div align="right"><font size="1">comments | forums</font></div><br>


And the index.shtml page had the following:
Code: Select all
<center><!--#include virtual="n3/news.txt" --></td></tr></table></center>


What am I doing wrong?
MrCodeDude
 
Posts: 20
Joined: Tue Apr 02, 2002 2:58 am

Postby Dale Ray » Mon Dec 22, 2003 6:02 am

I tested this style on a local copy of Coranto and it works:

Code: Select all
<If: Sub: isNewDate>
    <If: Field: CustomField_FirstLast eq "First">
        <table border="1" width="570" cellpadding="7"><tr><td>
    <If: Else>
         </td></tr></table>
         <table border="1" width="570" cellpadding="7"><tr><td>
    </If>
          <h2><Field: Date></h2>
</If>
<h3><Field: Subject></h3>
<p>Posted by: <Field: User></p>

<p><Field: Text></p>

<If: Field: CustomField_FirstLast eq "Last">
    </td></tr></table>
</If>


The custom field I used was FirstLast with the values of First, Last, Middle. I made Middle the default value so that button is selected when you enter news, you only have to change it for the first and last item.

I removed some of MrCodeDude's formatting to make the style more readable.

For a given set of news items you can only have one profile using this type of style, unless the filtering is the same on both profiles. If you are just using multiple profiles on the same news items with different formatting in the style that WILL work since the first and last items will be the same.

This does work, but it is up to you to manually mark the first and last items. This is easiest with the default sorting since the modify news page will show your items in the same order that they are processed by the style.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Dale Ray » Mon Dec 22, 2003 6:40 am

Here is a revised and tested version of LoneOwl's method:

Code: Select all
<If: Sub: isNewDate>
<PerlCode>
   if (not $startnew) {
   $divider = "<table border=\"1\" width=\"570\" cellpadding=\"7\"><tr><td>";
   } else {
    $divider = "</td></tr></table>\n<table border=\"1\" width=\"570\" cellpadding=\"7\"><tr><td>";
   }
$startnew++;
</PerlCode>
<Field: divider>
</If>
<h3><Field: Subject></h3>
<p>Posted by: <Field: User></p>

<p><Field: Text></p>


You must include the closing tag for the last cell, row, and table in the page you are including the news and in order to not screw up you page's HTML there must be at least one item using this method.

LoneOwl - thanks, you forced me to learn a little about using perl code in styles. :)
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby MrCodeDude » Mon Dec 22, 2003 7:09 am

Dale Ray wrote:Here is a revised and tested version of LoneOwl's method:

Code: Select all
<If: Sub: isNewDate>
<PerlCode>
   if (not $startnew) {
   $divider = "<table border="1" width="570" cellpadding="7"><tr><td>";
   } else {
    $divider = "</td></tr></table>\n<table border="1" width="570" cellpadding="7"><tr><td>";
   }
$startnew++;
</PerlCode>
<Field: divider>
</If>
<h3><Field: Subject></h3>
<p>Posted by: <Field: User></p>

<p><Field: Text></p>


You must include the closing tag for the last cell, row, and table in the page you are including the news and in order to not screw up you page's HTML there must be at least one item using this method.

LoneOwl - thanks, you forced me to learn a little about using perl code in styles. :)
OMG, thank you so much. It worked. Image to both of you!
MrCodeDude
 
Posts: 20
Joined: Tue Apr 02, 2002 2:58 am

Postby Dale Ray » Mon Dec 22, 2003 7:20 am

MrCodeDude wrote:OMG, thank you so much. It worked.


Glad it worked. As it sometimes happens, I learned something in the process of helping out. Seems like we both benefit :!:
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Mon Dec 22, 2003 7:57 am

Great work guys! :-) Like you said Dale Ray, this question has been raised a couple of times before, maybe the final example should be cleaned further and then serve as an example in the "All questions answered here"-newbie thread?
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 LoneOwl » Mon Dec 22, 2003 11:52 am

A lot of what's done in PerlCode is common... Mainly it's defining/setting variables and dealing with truthness. There are three 'truths' in perl: non empty string, non zero number, and zero but true. Plus 'if this and that' and 'if this or that' is another thing.... But I've been doing so much perl recently and so little Coranto styles, perl's natural....it's scary.
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Parahead » Mon Dec 22, 2003 2:16 pm

LoneOwl wrote:A lot of what's done in PerlCode is common...
I do not disagree with you LoneOwl? I was just making a suggestion so that the next time the questions pops up there is a clean easy-to-understand-and-customize solution for this.
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 Parahead » Thu Jun 03, 2004 9:03 pm

If anyone tries to implement this I would just like to mention that $startnew should be replaced with $startnew{$ProfileName} in order to fully work when using several profiles...
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 Demoric » Thu Jun 10, 2004 2:57 am

I thought I'd drop in the style I use on my site that's based on these posts, and a little more. It shows dates like 1st, 2nd. It Shows day first, and some other goodies. Basically I hope this helps somebody.

<PerlCode>
#Comment Area
#To add to shtml page: "<!--#include virtual="/cgi-bin/coranto/news.txt" -->"
#Put anything you want included in the last frame underneath
#Add this link to close frame "</td></tr></table>"
</PerlCode>

<PerlCode>
if( $Day > 3 && $Day < 21 ) {
$Day = $Day.'th';
}elsif( $Day % 10 == 1 ) {
$Day = $Day.'st';
}elsif( $Day % 10 == 2 ) {
$Day = $Day.'nd';
}elsif( $Day % 10 == 3 ) {
$Day = $Day.'rd';
}else {
$Day = $Day.'th';
}
</PerlCode>

<If: Sub: isNewDate>
<PerlCode>
if (not $startnew) {
$divider = "<table border=\"1\" width=\"90%\" cellpadding=\"7\" align=\"center\" style=\"background-color: white\"><tr><td>";
} else {
$divider = "</td></tr></table><p>&nbsp;</p>\n<table border=\"1\" width=\"90%\" cellpadding=\"7\" align=\"center\" style=\"background-color: white\"><tr><td>";
}
$startnew++;
</PerlCode>
<Field: divider>

<h2 style="margin-top: 0; margin-bottom: 0">
» <Field: Weekday>: <Field: Month_Name> <Field: Day>, <Field: Year></h2>

</If>
<p><b><Field: Subject></b> -- <small>Posted by
<If: Field: UserField_Email>
<a href="mailto:<Field: UserField_Email>"><Field: User></a>
<If: Else>
<Field: User>
</If>
at <Field: Hour>:<Field: Minute> <Field: AMPM> (CDT)</small><br>
<hr>
<p><Field: Text></p>
<p align="right"><font size="1" face="Arial">
[ <a href="/cgi-bin/coranto/coranto.pl?nid=<Field: newsid>&action=modify-edit">Edit</a> | <If: Field: CustomField_YaBB_ID><a href="<PerlCode>$newshtml .= "$CConfig{'/cgi-bin/yabb/'}/YaBB.pl?board=$CustomField_YaBB_Board\&action=display&num=";</PerlCode><Field: CustomField_YaBB_ID>" target=_blank>Discuss In Forums</a> | <If: Else><a href="/cgi-bin/yabb/YaBB.pl">Go To Forums</a> | </If>
<A HREF="#top">Back to Top</A> ]</font></p>
Jaydium - The Freedom Of Choice
News, Freeware, and more
User avatar
Demoric
 
Posts: 48
Joined: Mon May 24, 2004 6:42 pm
Location: S.E. Kansas


Return to Troubleshooting

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron