Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP and MovableType (add image to young entries)

Posted on 2004-09-03
1
Medium Priority
?
302 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

824 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