Solved

PHP and MovableType (add image to young entries)

Posted on 2004-09-03
1
296 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

807 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