Solved

PHP and MovableType (add image to young entries)

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

920 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

13 Experts available now in Live!

Get 1:1 Help Now