Today's Posts Only

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
snorkle256
Regular
Posts: 10
Joined: Tue Jan 09, 2007 5:45 pm
Location: Wisconsin
Contact:

Today's Posts Only

Post by snorkle256 »

I was wondering how I could go about getting my Serendipity installation to only show the posts of the current day while allowing the visitor to go back day by day to see posts or forwards to see future posts.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Today's Posts Only

Post by garvinhicking »

Hi!

Well, that's a bit more complicated. But since serendipity is flexible, you do have some options. :-)

Let's go through them:

1. If you only post one entry a day, you could just go into your s9y configuration and set the "number of entries per page" to "1".

2. You could setup a custom index file that forwards the user with a small php script to a URL like this:

Code: Select all

<?php
header('Location: http://yourhost/serendipity/archives/' . date('Y/m/d') . '.html');
?>
Insert that into a file like index.html - only if PHP is parsed in files with .html extensions on your server. If that doesn't work, you would need to call the file like myindex.php and edit your .htaccess file to set "DirectoryIndex /myindex.php".

3. You can edit your entries.tpl template file. Depending on the template you should see a loop like this:

Code: Select all

{foreach from=$entries item="dategroup"}
That will make sure that all entries are shown on a page. To restrict it to the entries of the current day, you need to change it to this:

Code: Select all

{assign var="current_shown" value="no"}
{foreach from=$entries item="dategroup"}
{$current_shown == 'no'}
<!-- This is the first block of entries for the first date of this page -->
... here comes all the code that currenty is shown after the {foreach} loop until the end of the {/foreach}. There should also be a second {foreach} loop that needs to be part of this, to print multiple entries on the same date ...
{assign var="current_shown" value="yes"}
{else}
<!-- Nothing to print here, the date is discarded -->
{/if}
The tricky part of the loop is that you need a temporary variable "current_shown" that is set once a date has been emitted. The first dategroup always comes at the beginning of the loop, so the loop needs to simply ensure that only the first block is shown, and everything else is discarded.

I'm not fully sure if you might get trouble that certain posts are then hidden from your page display. If that happens, you will need to create an event plugin that changes the serendipity_fetchEntries() call SQL structure to only return entries of a given date (today, or the ones coming from an URL query string). Building such a plugin requires PHP knowledge, though.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
snorkle256
Regular
Posts: 10
Joined: Tue Jan 09, 2007 5:45 pm
Location: Wisconsin
Contact:

Post by snorkle256 »

Thank you for such a quick reply.

Option one would not work for me as I usually do post more than one post each day.


Option two might actually work so I will be given it a shot because it seems easier than option three.

Option three would be my preferred method if I actually had php knowledge to complete the code or write new.
snorkle256
Regular
Posts: 10
Joined: Tue Jan 09, 2007 5:45 pm
Location: Wisconsin
Contact:

Post by snorkle256 »

Method two works correctly for the most part. However it does not co-operate with the sidebar login. I am going to see what i can do to play around with that.
Post Reply