Solved

PHP and MovableType (add image to young entries)

Posted on 2004-09-03
1
291 Views
Last Modified: 2008-03-06
I'm using MovableType 2.661 and just learning PHP.  I'm trying to add a 'new' image/icon beside the title (in the archive) of every post that is less than 45 days old. Since my php skills are seriously lacking, I was hoping for some help.

Here's what I started with.


<?php
$mtentrydate = <$MTEntryDate format="%m/%d/%y"$>;
$expiredate = 45;    
$postdate = getdate(strtotime('$mtentrydate'));
$startyear = $postdate['year'];
$startdate = $postdate['yday'];
$thisday = getdate();    
$thisyday = $thisday['yday'] + 1;
$thisyear = $thisday['year'];

if ($thisyear > $startyear) {
die;
}
else {
$expcompare = $thisyday - $startdate;  
if ($expcompare < $expiredate) {
print ('<img src="http://www.mysite.com/images/new_tag.gif" alt="New Post!" width="25" height="9">');
}
else {
die;
}
}
?>
 


Please feel free to start your reply by saying, "You're right stuboo, your PHP skills are definately lacking".

Thanks in advance for your help.

stuboo
0
Comment
Question by:stuboo
1 Comment
 
LVL 36

Accepted Solution

by:
Zyloch earned 50 total points
ID: 11976942
>>You're right stuboo, your PHP skills are definately lacking

Hi

Started it just like you asked :) but seriously, your php skills aren't that lacking. PHP, like many other languages, is just some sytax, which you seem to understand, and a bunch of functions that you learn through experience and necessity.
(ok, so maybe that's a little harsh, but it's the same concept)

First of all, you'd probably want to switch from die to exit, unless you have no script following your ?> tag, because exit will stop the php script from continueing but still print any HTML you have after the end ?> tag whereas die will stop EVERYTHING, so if you have an open tag, you're "screwed" sometimes.

You might try something like this:

<?php
$mtentrydate = <$MTEntryDate format="%m/%d/%y"$>;
$expiredate = 45;    
$postdate = strtotime('$mtentrydate');
$now = time();

if ($now-$postdate<3888000) {
   echo('<img src="http://www.mysite.com/images/new_tag.gif" alt="New Post!" width="25" height="9">');
}
else {
exit;
}
?>


Regards,
Zyloch
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now