x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

Start on for recent content

Start On Today - Related article

Using Weblog parameter START_ON to restrict content

If you want to restrict the entries displayed to only those that are “recent” but you do not want to use the expiration date, you can do this with a combination of PHP and the start_on weblog parameter. This might be useful in a case where you don’t necessarily want older entries to disappear from site searches, as would be the case if you use the expiration date. (Note that the weblog entries parameter “show_expired” can be used to display expired entries, but this parameter is not available in the search module of EE version 1.3.)

Be sure to set PHP parsing to “on” and to “input” for the template in question.

Then use something like the following:

{exp:weblog:entries weblog="{master_weblog_name}"
<?php
$cutoff_date
=
date("Y-m-d H:i", mktime(date("H"), date("i"), 0, date("m")-1, date("d"), date("Y")) );


echo
' start_on="', $cutoff_date, '" '; ?>
orderby
="date" sort="desc"}

This would limit the entries to only those within the last month. If you wanted, say, one week, then you would use a $cutoff_date of:

$cutoff_date =
date("Y-m-d H:i", mktime(date("H"), date("i"), 0, date("m"), date("d")-7, date("Y")) );

It’s recommended to use the PHP mktime function because it automatically handles daylight savings time.

References:

docs

Category:Templates Category:Entries Category:PHP

Categories: