Last two days of news?

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

Last two days of news?

Postby Broomsy » Mon Oct 14, 2002 10:23 am

Ok I have got my default category up to show the last two days of news. I made 8 posts on the 10th of this month and 1 on the 11th. I then came in today and deleted the one from the 11th and made a post today on the 14th. I was expecting to see that the news for the 10th would still show but it didnt. Why is that? I really want this to happen as sometimes I dont post everyday
Broomsy
 
Posts: 244
Joined: Wed Jan 10, 2007 10:25 am
Location: UK

Postby Sumaleth » Mon Oct 14, 2002 11:34 am

That filter option counts back two days from the current day, not the previous two days with news posts. So it's including news from the 14th and 13th.

I'm not aware of any addons that would do what you're after, but there would certainly be a way to do it with some perl code in the Style. (ie. turn off filtering and let the perl code in the style determine what news items get included)
Sumaleth
 
Posts: 1366
Joined: Thu Jul 11, 2002 4:31 pm

Postby Broomsy » Mon Oct 14, 2002 12:03 pm

Oh right. I get you. At least I know that it is possible. Only trouble is I have no experience in perl. Could anybody help. Also would this be possible in the headlines. I want to display say 15 headlines but only from that day. When a new news story is posted the next day all headlines are erased and started again for that day. Thanks in advance for anyones help
Broomsy
 
Posts: 244
Joined: Wed Jan 10, 2007 10:25 am
Location: UK

Postby Sumaleth » Mon Oct 14, 2002 3:08 pm

Something like this:

Code: Select all
<If: Sub: isNewDate>
<PerlCode>$daycount++;</PerlCode>
</If>

<PerlCode>
if ($daycount < 3) {
  $newshtml .= qq~

<p>Put the news style here using normal HTML code.<br>
<p>Use $Subject instead of <Field: Subject> for example.<br>

  ~;
}
</PerlCode>

That's probably not the neatest Style code ever, but I'm not completely familiar with Style stuff.

Essentially the idea is that if the 'isNewDate' subroutine reports that it's a different day than the previous news item (which is what it does), then it increases $daycount by one.

Then in the next bit of code, it only adds the current news item if $daycount is less than 3. So theoretically it'll only include news items from the first two days it comes across.

I've done that last bit in Perl because I don't think Coranto can do a <If: Field: daycount < 3>. You still build the Style the same as before, but instead of <Field: blah> you use $blah.

Give it a try anyway. Can't hurt.
Sumaleth
 
Posts: 1366
Joined: Thu Jul 11, 2002 4:31 pm

Postby Broomsy » Mon Oct 14, 2002 3:15 pm

Thanks for your reply but it didnt work. It may be because I have this

<If: Sub: isNewDate>
<h4><Field: Date></h4>
</If>

before my news story. Any other ideas anybody?
Broomsy
 
Posts: 244
Joined: Wed Jan 10, 2007 10:25 am
Location: UK

Postby Sumaleth » Mon Oct 14, 2002 3:25 pm

Change it to:

Code: Select all
<If: Sub: isNewDate>
<h4><Field: Date></h4>
<PerlCode>$daycount++;</PerlCode>
</If>

<PerlCode>
if ($daycount < 3) {
  $newshtml .= qq~

<p>Put the news style here using normal HTML code.<br>
<p>Use $Subject instead of <Field: Subject> for example.<br>

  ~;
}
</PerlCode>

So it uses the top If statement for both tasks.
Sumaleth
 
Posts: 1366
Joined: Thu Jul 11, 2002 4:31 pm

Postby Broomsy » Tue Oct 15, 2002 11:05 pm

Thankyou for your continuing help. I let a day slip past to give it a test but it didnt work. i did a full rebuild yesterday as well to make sure. If you go to my site you can see the post for Wednesday shows but not the posts from Monday :(
Broomsy
 
Posts: 244
Joined: Wed Jan 10, 2007 10:25 am
Location: UK

Postby tkaplan06 » Wed Mar 16, 2005 1:33 am

Can anyone take a look at this and see if they can get it to work? It would be extremely helpful for my installation of Coranto, but I can't get this code to work.

Tom
tkaplan06
 
Posts: 9
Joined: Wed Mar 09, 2005 2:28 am

Postby Dale Ray » Wed Mar 16, 2005 9:11 am

Try this:
Code: Select all
<PerlCode>
# change the value of news_days to suit your needs
$news_days = 2;
$done = 0;
if (&isNewDate()) {
if (not $counter{$ProfileName}) {
   $counter{$ProfileName} = 1;
   } else {
   $counter{$ProfileName}++;
}
$dayCount = $counter{$ProfileName};
if ($dayCount > $news_days) {
$done = 1;
}
# set a header for the new day
$day_header = "The sun came up today\n";
} else {
$day_header = "";
}
if (!$done){
</PerlCode>
<Field: day_header>
Posted on: <Field: Date> by <Field: User>
<Field: Subject>
<Field: Text>
</If>


Paste this into a text editor and delete the spaces from the ends of each line that the forum inserts.

Change the value of $news_days to the number of days news you want to display.

Make sure that your profile filters don't cut the news off before the style code does. Test with all profile filtering off to be sure it is working correctly.

This is not tested, but you should be able to limit the display to x number of days or x number of items by using this and filter by number in your profile. For example if filter by number is set to 20 and there are 25 posts on the first two days of news you will only see 20. If the days are set to 2 and there are less than 20 posts in the first two days the style will cut off the display at two days.

Your profile must be sorted by reverse or reverse chronological order for this to work properly (all the news from the 2 days).

Substitute your own style after the </PerlCode> tag and before the </If>

This doesn't stop Coranto from processing the items for the other days in your profile, there just won't be any visible output on a webpage.

You can use Coranto fields to build the header for each new day, for example:


Code: Select all
$day_header = "$Weekday.", ".$Month_Name." ".$Month_Day.", ".$Year";


Builds a header that looks like:

Wednesday, March 16, 2005

This was tested with a very small sampling of data using V 1.24 of Coranto. Make sure you have a backup.

Suggestions on code improvement are welcome. If you were to see me looking up almost everything in the perl books I keep by the computer table you might not even try this out :wink:
Dale Ray
User avatar
Dale Ray
 
Posts: 1004
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Lumberjack » Wed Mar 16, 2005 11:02 am

Can't you use 'Filter by day' in the profile settings? If that doesn't work, Parahead just released a new addon (see Addon Releases forum) which may help with this.

As for that code, it seems that $dayCount is not required, you can just use $counter{$ProfileName} which has the same value. Also you seem to have too many curly brackets around $day_header.
Not sure exactly what you are trying to do at $day_header, but if you move this code somewhere higher, then you can continue from
Code: Select all
if ($dayCount > $news_days) {

..without having to use $done at all. For example:
Code: Select all
# set a header for the new day
$day_header = "The sun came up today\n";
} else {
$day_header = "";
}

unless ($dayCount > $news_days) {
</PerlCode>
<Field: day_header>
Posted on: <Field: Date> by <Field: User>
<Field: Subject>
<Field: Text>
</If>

I'm assuming the </If> will close the curly brackets for unless? If not you could change unless to if, and use ! to negate the check?
Lumberjack
 
Posts: 555
Joined: Wed Jan 10, 2007 7:22 pm
Location: Oxford, UK

Postby LoneOwl » Wed Mar 16, 2005 11:08 am

Dale Ray wrote:Suggestions on code improvement are welcome. If you were to see me looking up almost everything in the perl books I keep by the computer table you might not even try this out :wink:
I prefer using perldoc, must friendlier for me, and far, far more in depth. But I'll take your offer.

Code: Select all
<PerlCode>
# change the value of news_days to suit your needs
$news_days = 2;
if (&isNewDate()) {
    $counter{$ProfileName}++;
    # set a header for the new day
    $day_header = <<"END_HEADER";
    The sun came up today.
END_HEADER
}
else {
    $day_header = '';
}
return if $counter{$ProfileName} <= $news_days;
</PerlCode>
<Field: day_header>
Posted on: <Field: Date> by <Field: User>
<Field: Subject>
<Field: Text>
Oh, and this should compile a tad better....
Code: Select all
$day_header = "$Weekday, $Month_Name $Month_Day, $Year";
When it comes to any code for Coranto, don't bother making it run under `use warnings;` because, well, Coranto won't, so doing much more is unneeded. Also, <Field: Name> will work in <PerlCode> tags, due to a "generalization" of how it's done.... It would actually be possible to change that, but...it's unneeded.
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Lumberjack » Wed Mar 16, 2005 11:25 am

Hehe yeah alright then, that's probably better.
Lumberjack
 
Posts: 555
Joined: Wed Jan 10, 2007 7:22 pm
Location: Oxford, UK

Postby Dale Ray » Wed Mar 16, 2005 7:27 pm

Lumberjack wrote:Can't you use 'Filter by day' in the profile settings? If that doesn't work, Parahead just released a new addon (see Addon Releases forum) which may help with this.

Filter by Day works fine (on V 1.24) with the default sorting (reverse chronlogical - newest first). The results I get from using filter by day and the style I posted above are the same. Lumberjack, which addon by Parahead are you referring to?

If you sort chronological the filter by day still returns the most recent x days of news. The style above returns the x oldest days.

Coranto's behaviour regarding filter by day seems to have changed since this thread started in October, 2002.

Sumaleth wrote:That filter option counts back two days from the current day, not the previous two days with news posts.

It seems that Coranto does not do this any longer, it does indeed (in my limited testing) process news from the last X posting days even if they are more than X days old or are separated by more than X days. Anyone know when this was "fixed"?

I saw the new post, thought it wouldn't be too hard to do what was asked and took it on as a puzzle to solve. I almost never filter news by day so had not dealt with this before.

LoneOwl, I will look at the code you posted and check it out. Thanks for the suggestions.
Dale Ray
User avatar
Dale Ray
 
Posts: 1004
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Dale Ray » Wed Mar 16, 2005 8:32 pm

These statements were wrong in my previous post-
Dale Ray wrote:Filter by Day works fine (on V 1.24) with the default sorting (reverse chronological - newest first). The results I get from using filter by day and the style I posted above are the same.

It seems that Coranto does not do this any longer, it does indeed (in my limited testing) process news from the last X posting days even if they are more than X days old or are separated by more than X days. Anyone know when this was "fixed"?

The data I was using had dates in the future (set Using ChangeDateNew) so the results were the same because Coranto tests for x number of days from now into the past, future items were not filtered out. I reset the dates to all be in the past and Coranto will not display ANY news if your Filter by Day setting is set to X and all of your news is older than X days.

Also, if you have news from today and news from last week (say 7-14 days old) a Filter By Day setting of 2 will only display today's news. (With all news dates in the past)

Sorry if I confused anyone besides myself.

I am gong to do more detailed testing of sorting in Coranto and report back. I have fallen into the subject of sorting lately.

See these forum topics:

SortOrders Request - Sort by Date and second field

and

Addon Release: Profile Numeric Filter

for other discussions of sorting.

tkaplan06 wrote:Can anyone take a look at this and see if they can get it to work? It would be extremely helpful for my installation of Coranto, but I can't get this code to work.

tkaplan06,

Ignoring all of the discussion of code, the style I posted (or LoneOwl's) should do what you need.
Dale Ray
User avatar
Dale Ray
 
Posts: 1004
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Dale Ray » Thu Mar 17, 2005 9:03 am

LoneOwl,

This line:

return if $counter{$ProfileName} <= $news_days;

actually causes the style to skip the number of days that $news_days is set to (which could also be useful)

I changed it to:

return if $counter{$ProfileName} > $news_days;

and it works fine.
Dale Ray
User avatar
Dale Ray
 
Posts: 1004
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Next

Return to Troubleshooting

Who is online

Users browsing this forum: No registered users and 1 guest

cron