How do I automatically show the most recent entry and have it expire after two weeks? If there is no new entry within two weeks show nothing. This seems relatively easy but I can’t figure it out for the life of me.
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
August 27, 2007 4:06pm
Subscribe [4]#1 / Aug 27, 2007 4:06pm
How do I automatically show the most recent entry and have it expire after two weeks? If there is no new entry within two weeks show nothing. This seems relatively easy but I can’t figure it out for the life of me.
#2 / Aug 28, 2007 10:22am
You’ll have to do two things:
First, in your weblog entries tag put in {exp:weblog:entries weblog="your-weblog-name" limit="1"} plus what ever entry fields you are using such as {body} {summary}. Of course, close it with {/exp:weblog:entries}
Then on the actual entry, under PUBLISH or EDIT, if you’ve already created it, click on DATE then set the EXPIRATION DATE to two weeks from the initial ENTRY DATE. You’ll have to set the dates for each entry.
Hope that helps.
#3 / Aug 28, 2007 2:10pm
Thanks for your help but is there no way to set this up automatically? I basically just want the entry to not display on the home page after two weeks. It will show up within the interior of the site, but the home page will just need to show the entry for two weeks. Setting it for each entry might be tricky too because there may be multiple people editing it, and it would need to be set for two weeks every time someone edits the entry.
#4 / Aug 28, 2007 3:07pm
There is a parameter you can set: Start_On
You’ll need to use some sort PHP code:
$current_time = $LOC->decode_date('%Y-%m-%d %g:%i %A', $LOC->now-1209600);1209600 is two weeks ago.
#5 / Aug 28, 2007 3:30pm
Thanks Sue, I was looking at that but I’m unclear how to set this up in my template. I get the enable PHP part, but what I don’t get is how the logic works. Do I set up a range of 1209600 seconds and put a Start_On and Stop_Before? If this is the way, how do I do that with PHP? If not how can Start_On disappear entries after two weeks? Doesn’t this just show entries starting on a certain date?
#6 / Aug 28, 2007 3:45pm
I think you can just the
display_by="day" limit="14"added to your {exp:weblog:entries} tag. I’ve never used it, but I believe that’s what its for.
#7 / Aug 28, 2007 3:55pm
Just tested it on a temp page, and the
{exp:weblog:entries weblog="press" display_by="day" limit="14" category="45|48"}should work for you. Make sure no pagination is involved, because that seems to act as an override. Well it actually paginates after the specified limit. So if you specify a single day, then pagination marks well show for each day. Kind of cool, but not what your looking for, so just get rid the pagination code.
#8 / Aug 28, 2007 4:41pm
Thanks for the code but it still doesn’t work. Here is what I have:
<ul>{exp:weblog:entries weblog="mcri" display_by="day" limit="14"}
<li><a href="http://{path=mcri/index}">{title}</a></li>
{/exp:weblog:entries}</ul>Here is the link to the page:
The entry dates for those entries on the right are between 7/25/2007 and yesterday. It should only show those entries with a date no later than 8/14/2007. Any idea what I’m doing wrong?
#9 / Aug 28, 2007 5:26pm
I understand what you mean and need, but I don’t believe that the expiration date changes every time someone edits the entry. Meaning, that it wouldn’t need to be reset.
#10 / Aug 28, 2007 6:22pm
You don’t have a sort order specified. Possible my bad, since, I took it out of the code I posted accidently. I got rid of everything after the limit, so that you didn’t have to wade through the disable and status parameters. I meant to kill the category parameters not the sort parameters.
#11 / Aug 28, 2007 6:32pm
I’m using 1.5.2 so that should have cleared the bug.
I understand what you mean and need, but I don’t believe that the expiration date changes every time someone edits the entry. Meaning, that it wouldn’t need to be reset.
Actually it would need to be set because if someone edited the entry on day 12 I’d want it to stay up for 2 weeks after that. In this way there would always be the most recent changes displayed on the home page.
This is a good possible solution, not the best though, because it involves some manual date editing by the author each time they make a change. If EE can’t do this functionality then we have no other choice. I will need to add a “show_expired” parameter to all the pages that display the entry other than the home page, if we go this way.
Thanks for your help again grantmx, but if anyone out there knows of another possible solution, we’d be grateful. It’s always best to make the backend as user friendly as possible.
#12 / Aug 28, 2007 6:37pm
You don’t have a sort order specified. Possible my bad, since, I took it out of the code I posted accidently. I got rid of everything after the limit, so that you didn’t have to wade through the disable and status parameters. I meant to kill the category parameters not the sort parameters.
I changed it to this but it still doesn’t seem to work:
{exp:weblog:entries weblog="mcri" display_by="day" limit="14" sort="asc"}
<li><a href="http://{path=mcri/index}">{title}</a>
</li>
{/exp:weblog:entries}#13 / Aug 28, 2007 6:49pm
Try sort descending, but I also forgot, it actually counts days with posts, not days without. There maybe some other parameter that would modify that. I’d have to look. My sample page is here.
#14 / Aug 28, 2007 6:54pm
Okay, follow-up to the last, since I didn’t look at your code clearly. The sort parameter requires an orderby parameter. Well it might not be strickly required, but I believe you could get inconsistent results if you specify one without the other. See the User’s Guide
Updated: You should also read the section on display_by and associated tags. The guide even provides the code for using PHP to get the start_on_date. I know some people eschew manuals, but the EE one is very handy, especially as a reference.
#15 / Aug 28, 2007 7:32pm
Thanks for the help allgood2.
OK here’s my code now, but it still isn’t displaying properly:
{exp:weblog:entries weblog="mcri" display_by="day" limit="14" sort="desc" orderby="date"}
<li><a href="http://{path=mcri/index}">{title}</a></li>
{/exp:weblog:entries}Believe me, I practically have the manual memorized.😊
I’ve read about the display_by and start_on tags and php stuff, but I can’t get the logic into my pea brain head. If I have it start displaying today, how do I make it stop displaying entries that are 2 weeks old. I almost need some sort of filter that would only show entries dated between today and 2 weeks ago from today. It seems so simple but I just can’t figure it out. If I use the php to get a start_on date, how do I use the php to get a stop_before date?
Maybe I will just expire the entries. Perhaps that is the easiest solution…
Yet it seems so simple, arggh!