TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 29, 2024, 01:04:51 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,106
  • Total Topics: 21,213
  • Online today: 358
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online

Holiday Blocks

Started by Skhilled, November 27, 2015, 02:36:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Skhilled

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"></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.

// 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>';

Ken.

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.

Ken.

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.

Ken.

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.

Skhilled

Quote from: Ken. on November 27, 2015, 03:11:21 PM
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.

Quote from: Ken. on November 27, 2015, 03:26:15 PM
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.

Ken.

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.

Sayaka Maizono

Here, I made one that has multiple date support.

<?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.'
;
}

?>

lurkalot

Quote from: Skhilled on November 27, 2015, 02:36:29 PM
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.


Quote from: Sayaka Maizono on November 28, 2015, 03:25:26 AM

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




Skhilled

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.

Freddy

Thanks for the new block - a really good idea that one :)