Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP and MovableType (add image to young entries)

Posted on 2004-09-03
1
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

721 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