how to pull stack content based on the day of the week

Permalink
I was wondering if I can get some guidance on how to build some functionality. My client wants to display content depending on the day of the week. So if it is Monday, the Monday content should how up on the sidebar, and so forth. Can anyone guide me on how to do this in C5, I have done it in Drupal but not sure how to accomplish this in C5 since I am so new to this. I have tried the following code in the default.php but nothing pulls even thought I have a stack called Tuesday:

<?
$today = date("l");
  if($today == "Sunday")
  {
     $a = new GlobalArea('Sunday');
     $a->display();
  }
  elseif($today == "Monday")
  {
     $a = new GlobalArea('Monday');
     $a->display();
  }
  elseif($today == "Tuesday")
  {
     $a = new GlobalArea('Tuesday');

 
lucasmullens replied on at Permalink Reply
lucasmullens
To my understanding, Stacks are different than Global Areas. I'd first include all 7 Global Areas so they get generated in the database, and then your code should work. The 7 Global Areas should then be found in the stack page.
alpdog14 replied on at Permalink Reply
well i since I created the Tuesday stack already I changed my code to this:

<?
$today = date("l");
  if($today == "Sunday")
  {
   $a = Stack::getByName('Sunday');
   $a->display();
  }
  elseif($today == "Monday")
  {
     $a = Stack::getByName('Monday');
     $a->display();
  }
  elseif($today == "Tuesday")
  {
     $a = Stack::getByName('Tuesday');


But nothing still pulls, also I see somehow a Tuesday Global area was generated automatically but nothing still pulls
alpdog14 replied on at Permalink Reply
Ok I just added some content block to the Tuesday Global area and it showed up, so I believe it is working, but I am not sure how this Global Area was created? How do I create global areas?
alpdog14 replied on at Permalink Reply
Yeah its weird somehow a "Tuesday" global area was created but none of the other global areas were created from that php code. I also tried to added this code:

<?php
  $a = new GlobalArea('Sunday');
  $a->display();
?>


But a Sunday global area is not getting created. How does one create a global area, from reading the above code should work, right? I tried clearing my cache but still nothing.
alpdog14 replied on at Permalink Reply
Ok it took some time but Sunday eventually showed up maybe I am just impatient but it did seem to take a long time to get created in the DB
alpdog14 replied on at Permalink Reply
Nevermind, as soon as i created these outside of the "If" statement it looks like it generated quickly.
jordanlev replied on at Permalink Reply
jordanlev
For the record, global areas are created in one of two ways:

1) A page on your site that has a global area in it is viewed. So if you have $a = new GlobalArea('Whatever') in a page type template for your theme, then as soon as a page of that type is viewed in the browser the new 'Whatever' global area will be created by the system.

2) Via some code like this:
$arHandle = 'Whatever';
if (version_compare(APP_VERSION, '5.5.2', '<')) {
    //due to a bug in 5.5.0 and 5.5.1, Stack::getOrCreateGlobalArea() doesn't return the newly created global area stack
   Stack::getOrCreateGlobalArea($arHandle);
   $stack = Stack::getByName($arHandle);
} else {
   $stack = Stack::getOrCreateGlobalArea($arHandle);
}
$stack->display();
alpdog14 replied on at Permalink Reply
This does work but also my code did eventually create the global areas. The php that I posted does work as the day changes so does the content. This is also great because I can "copy to clipboard" the block from the specific global area to the associated webpage so the content is "mirrored" across all block/global areas do if one changes they all change. So I think all is working, thanks for all your help, so far this CMS is beating out Drupal in my experience.
jordanlev replied on at Permalink Reply
jordanlev
Ahh, yes -- I see how your code would also create the areas (because it's the same code that would be in a theme template, which triggers the automatic creation of it by the system).

Glad you're liking C5 -- I fell in love with it after really struggling with Drupal. Something about the way C5 works just fits my brain a lot better than Drupal.
alpdog14 replied on at Permalink Reply
Ok so I just checked my test site and it is not updating by the day of the week (Thurs), it did change to Wed after Tues but just checking it now, which it is Thurs, the stack did not update:http://yesiamprimary.com/brainsportz2/...

I did not change the code, does anyone know why this would update based on my pho code above with global areas, it was working or at least I thought it was.
jordanlev replied on at Permalink Reply
jordanlev
I wonder if the time zone on your server is different than your location? If the server is set to GMT, it might be 6, 8, or more hours off from your actual time (depending on where you live).
alpdog14 replied on at Permalink Reply
Actually it did switch, I think you are right for the server having a different time zone, can I change this in my PHP?
jordanlev replied on at Permalink Best Answer Reply
jordanlev
I think if you add something like this to your SITEROOT/config/site.php file, it should do the trick:
define('APP_TIMEZONE', 'America/Chicago');


For a list of all available time zone strings, seehttp://www.php.net/manual/en/timezones.php...