How to Create a PHP Editorial Calendar - Quantum Designers

How to Create a PHP Editorial Calendar

If you are Developer working for a publisher or media company , this tutorial may help you.

An Editorial Calendar is used to show the advertisers (clients),  the publication dates and ad deadlines dates.  The calendar also shows the main topic of each publication, in this example for a magazine issue.

In this tutorial,  I will show you the dynamic PHP calendar I created for http://www.diverseeducation.com

The calendar is dynamic because it gets automatically updated. In this example , it get updated every two weeks.

1 . Define arrays

I defined four arrays as follows:

$issue_date

$title

$ad_deadline

For the issue date, you enter all dates in ascending order. It’s important to note that the dates must be entered in MM/DD/YYYY format. Otherwise , the program will crash.

<table class="table responsive" width="auto" cellspacing="0" cellpadding="2" style="font-family:'Roboto': 17px">
<tbody>
<tr>
  <td width="122" align="center"><strong>Issue Date</strong></td>
  <td>
    <table border="0">
      <tbody>
        <tr>
          <td width="217" height="38" align="left">  

            </td>
          </tr>
        </tbody>
      </table></td>
 <td style="text-align: center;" width="109"><strong>Ad Deadline</strong></td>
</tr>  </tbody></table>
<table class="table responsive" cellspacing="0" cellpadding="2" style="font-family: 'Roboto Slab': 17px">
<?php
$issue_date = array (
"06/09/2022",
"06/23/2022",
"07/07/2022",
"08/18/2022",
"09/01/2022",
"09/15/2022",
"09/29/2022",
"10/13/2022",
"10/27/2022",
"11/10/2022",
"11/24/2022",
"12/08/2022");
?>

Here you will enter the main topic of the magazine edition. Same for the ad deadline.

You enter them in between quotes and separated by commas, same as you did for the issue date. On the page , this is the column showing in the center of the table.

$title = array (

"STEM - Science, Technology, Engineering & Math",
"HBCUs - Historically Black Colleges & Universities",
"Active Duty/Veteran Military Education/Virtual Education",
"Academic Kickoff",
"Hispanic Heritage Month",
"Recruitment & Retention/Top 100 Degree Producers",
"Careers in Higher Education",
"Native American Heritage Month",
"Health Sciences",
"Comm. Colleges - Top 100 Assoc. Degree Producers - Year in Review"

);
<?php
$ad_deadline = array (
"05/19/2022",
"06/02/2022",
"06/16/2022",
"07/28/2022",
"08/11/2022", 
"08/25/2022",
"09/08/2022",
"09/22/2022", 
"10/06/2022",
"10/20/2022",
"11/03/2022",
"11/17/2022" );
?>

2. Create the Loop

So far, we only have a page that displays text and dates. It doesn’t do anything for us. The code below , is what does the trick.

We need to create a for loop in order to go through the calendar dates and update accordingly.

Let’s break it in different parts to understand it better.

Since we are working with dates, we need to define a variable that will be equal to today’s date. The php built-in strtotime function converts the date into UNIX timestamp. To read more about this click here  https://www.php.net/manual/en/function.strtotime.php

<?php
$todays_date = date("m/d/Y"); 
$today = strtotime($todays_date);
?>

In the for loop below, we pass the variable $issue_date.

<?php

for($i=0; $i < count($issue_date); $i++)



Here we run an if statement, the logic is the following, if the magazine issue date is greater than today’s date, it means that row on the calendar still didn’t expire. So we display the data on that row. If the date has already passed, the row will not display.

{
if (strtotime($issue_date[$i]) >= $today)
{   
echo "<tr style=\"text-align: left;\"><td width='90' style='text-align:center';>
$issue_date[$i]</td><td width='480'>$title[$i]</td><td width='90' style='text-align:center';>$ad_deadline[$i]</td></tr>";  
}}

 The script will be looping through all dates every timethe page is loaded. This way, the calendar get automatically updated showing only the upcoming issue dates, topic and ad deadline dates.

 </table>
</div>
</div>
</div>
</body>
</html>

To view the live version of this script go to https://editorial-calendar.diverseeducation.com/

Facebook
Twitter
LinkedIn
Scroll to Top