Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

July 03, 2022, 06:46:27 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 193412
  • Total Topics: 21081
  • Online today: 62
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 49
Total: 49

Author Topic: Holiday Blocks  (Read 12519 times)

0 Members and 1 Guest are viewing this topic.

Offline Skhilled

  • Beta Tester
  • *
  • Posts: 1179
  • Once you stop learning, you stop living!
    • Doc Skillz
Holiday Blocks
« on: November 27, 2015, 07:36:29 AM »
Ever wish you could have a block that only shows on specific days and turns itself off the day after? Well, this block code can do just that! This code was created by Chen Zhen/Underdog for me and I've tested it with TP and it works.

All you have to do is change 2 lines in the code:

The date in this line:
Quote
$showBlock = array('month'=> 11, 'day' => 26);

And add your image in this line:
Quote
<div align="center">[img width= height=]http://mysite.com/some_image.jpg[/img]</div>';

You should also set Frame Options to: Do not use title/frame styles - or when the block disappears you'll still see part of it.

And set the block to: Do not allow block to collapse - or you'll still see the upshrink.

Code: [Select]
// opt month & day to show block
$showBlock = array('month'=> 11, 'day' => 26);

global $user_info;

$time = time()+($user_info['time_offset'] * 3600);
$date = array('month' => (int)date('m', $time), 'day' => (int)date('d', $time));

if ($showBlock['day'] != $date['day'] || $showBlock['month'] != $date['month'])
    return false;

// PHP code below this line
   
    echo '
    <div align="center"><img src="http://mysite.com/some_image.jpg"></div>';

Reading can seriously damage your ignorance!

Offline Ken.

  • Support Team
  • *
  • Posts: 4362
    • Our FamilyForum
Re: Holiday Blocks
« Reply #1 on: November 27, 2015, 07:56:56 AM »
Very nice!
Thank you Skhilled and thanks to Underdog for this handy little Block Code!  O0
" If everything seems under control, you’re not going fast enough." - Mario Andretti
Yesterday When I was Young.

Offline Ken.

  • Support Team
  • *
  • Posts: 4362
    • Our FamilyForum
Re: Holiday Blocks
« Reply #2 on: November 27, 2015, 08:11:21 AM »
Question:
Can this block be set to show for more than one day in succession? Example; you have an event/holiday that you would like to highlight for three days.

Thanks. :)
" If everything seems under control, you’re not going fast enough." - Mario Andretti
Yesterday When I was Young.

Offline Ken.

  • Support Team
  • *
  • Posts: 4362
    • Our FamilyForum
Re: Holiday Blocks
« Reply #3 on: November 27, 2015, 08:26:15 AM »
Of course it could be used in three separate blocks, with them set to display one after the other, on each successive day, in order and having individual content for each day.  O0
" If everything seems under control, you’re not going fast enough." - Mario Andretti
Yesterday When I was Young.

Offline Skhilled

  • Beta Tester
  • *
  • Posts: 1179
  • Once you stop learning, you stop living!
    • Doc Skillz
Re: Holiday Blocks
« Reply #4 on: November 27, 2015, 08:37:27 AM »
Question:
Can this block be set to show for more than one day in succession? Example; you have an event/holiday that you would like to highlight for three days.

Thanks. :)
As I was posting that I just realized that someone was going to ask about that! LOL

I assume you could modify the array for the day in some way to make it work.

Of course it could be used in three separate blocks, with them set to display one after the other, on each successive day, in order and having individual content for each day.  O0
Yes, that could work too.

Reading can seriously damage your ignorance!

Offline Ken.

  • Support Team
  • *
  • Posts: 4362
    • Our FamilyForum
Re: Holiday Blocks
« Reply #5 on: November 27, 2015, 09:32:46 AM »
I think the 'different block for each day' idea may be  better way to go in some cases because you could include a different image or message for each day.
" If everything seems under control, you’re not going fast enough." - Mario Andretti
Yesterday When I was Young.

Offline Sayaka Maizono

  • Beta Tester
  • *
  • Posts: 31
  • $("div.content:dd").hide();
Re: Holiday Blocks
« Reply #6 on: November 27, 2015, 08:25:26 PM »
Here, I made one that has multiple date support.

Code: [Select]
<?php

/*
@block Show Days
@author Rhode Fey (Sayaka Maizono)
*/

/*
Usage:
fill $dates array with arrays of the following:
array('month' => integer, 'day' => integer),
Example:
array('month' => 11, 'day' => 26),
array('month' => 11, 'day' => 26),

This will show only on November 26 and November 27
*/

$dates = array(
array('month'=> 11'day' => 26),
array('month'=> 11'day' => 27),
array('month'=> 11'day' => 28),
);

/*
 *
*/

global $user_info;

$time time() + ($user_info['time_offset'] * 3600);
$current_date = array('month' => (int) date('m'$time), 'day' => (int) date('d'$time));

$show false;

foreach (
$dates as $k => $date)
{
if (empty($date))
continue;

if ($date['month'] == $current_date['month'] && $date['day'] == $current_date['day'])
{
$show true;
continue;
}
}

if (
$show)
{
    echo 
'
Some html if you want to show if it is the date.'
;
}
else
{
echo '
Some html that you want to show if it is not the date.'
;
}

?>

Offline lurkalot

  • Administrator
  • *
  • Posts: 7405
    • Camera Craniums
Re: Holiday Blocks
« Reply #7 on: November 28, 2015, 05:34:37 AM »
Ever wish you could have a block that only shows on specific days and turns itself off the day after? Well, this block code can do just that! This code was created by Chen Zhen/Underdog for me and I've tested it with TP and it works.



Here, I made one that has multiple date support.


@ Skhilled and Sayaka, thanks to both of you.  Haven't tried these snippets yet, but I'm sure they will be useful.  O0




Offline Skhilled

  • Beta Tester
  • *
  • Posts: 1179
  • Once you stop learning, you stop living!
    • Doc Skillz
Re: Holiday Blocks
« Reply #8 on: November 28, 2015, 09:44:37 AM »
Thanks, Sayaka! I knew the array needed to be set up that way but way not sure how to code the rest so it would work.

Reading can seriously damage your ignorance!

Offline Freddy

  • Moderator
  • *
  • Posts: 1615
    • AiDreams
Re: Holiday Blocks
« Reply #9 on: November 28, 2015, 09:48:31 AM »
Thanks for the new block - a really good idea that one :)

Offline Skhilled

  • Beta Tester
  • *
  • Posts: 1179
  • Once you stop learning, you stop living!
    • Doc Skillz
Re: Holiday Blocks
« Reply #10 on: November 29, 2015, 02:16:16 PM »
I got tired of waking up and realizing that I had forgotten or need to add something for a holiday on my site which is how I came up with the idea...a "set it and forget" type of thing. I've created blocks for every holiday with an image and now I don't have to deal with it except for the ones that don't have a specific date like Thanksgiving which is the last Thursday of that month.

Reading can seriously damage your ignorance!

Offline Sayaka Maizono

  • Beta Tester
  • *
  • Posts: 31
  • $("div.content:dd").hide();
Re: Holiday Blocks
« Reply #11 on: November 29, 2015, 03:36:32 PM »
I can make you a block that will display things based on various dates if you want.

Offline william777

  • Full Member
  • ***
  • Posts: 122
Re: Holiday Blocks
« Reply #12 on: November 30, 2015, 01:09:24 PM »
 O0

Offline Sayaka Maizono

  • Beta Tester
  • *
  • Posts: 31
  • $("div.content:dd").hide();
Re: Holiday Blocks
« Reply #13 on: November 30, 2015, 06:45:52 PM »
Code: [Select]
<?php

/**
 * @block Custom Dates
 * @author Rhode Fey (Sayaka Maizono)
 * @version 1.0.0
 * @for TinyPortal
*/

global $user_info;

$time time() + ($user_info['time_offset'] * 3600);
$current_date date('m'$time) . '-' date('d'$time);

if (
$current_date == '12-25')
{
echo '
Merry Christmas!'
;
}
elseif (
$current_date == '1-1' || $current_date '12-31')
{
echo '
Happy New Year!'
;
}
elseif (
$current_date == '7-4')
{
echo '
Happy Independence Day!'
;
}
// Default if current date is not specified.
else
{
echo '
Hello!'
;
}

?>

Offline Skhilled

  • Beta Tester
  • *
  • Posts: 1179
  • Once you stop learning, you stop living!
    • Doc Skillz
Re: Holiday Blocks
« Reply #14 on: December 01, 2015, 07:59:01 AM »
Very simple but works! :)

Reading can seriously damage your ignorance!