Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-11-20 12:17:33

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Auto-rotation of the skin layer of themes by dates/season/holidays?

Let’s say I don’t want to do any deep structural changes with themes, but just want to change the ‘skin’ aspect of my theme, site-wide, on a seasonal basis, but without me having to manually switch it every three months.

How might that be approached? Not possible yet out of box?

Offline

#2 2019-11-20 12:44:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,485
Website GitHub

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

You’re probably best off doing this in your template via conditionals. You can probably use <txp:evaluate> to test if the date, for example, lies within a range and include a different Stylesheet based on the result.

Edit: I’ll leave it as homework for Oleg to provide the most efficient example ;)

Last edited by Bloke (2019-11-20 12:46:06)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#3 2019-11-20 13:44:47

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

You can do it fairly simply with etc_date but I am sure evaluate can do something similar.

<txp:etc_if_date value="09-23 | 12-21" format="%m-%d">
	<txp:css format="link" media="" name="autumn" />
</txp:etc_if_date>
<txp:etc_if_date value="12-22 | 03-20" format="%m-%d">
	<txp:css format="link" media="" name="winter" />
</txp:etc_if_date>

Offline

#4 2019-11-20 13:58:08

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

I’ll second that. I’ve used etc_date for exactly this for years.

<txp:evaluate> may be more efficient, but etc_date works and is easy to use.

Offline

#5 2019-11-20 14:15:45

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

Thanks all.

Offline

#6 2019-11-20 20:09:49

etc
Developer
Registered: 2010-11-11
Posts: 5,683
Website GitHub

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

Bloke wrote #320143:

I’ll leave it as homework for Oleg to provide the most efficient example ;)

Sorry, my kids are my exclusive homework furnishers :-) A hint: you can register PHP date function via Advanced options for use in <txp:evaluate />.

Offline

#7 2019-11-20 22:56:35

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

etc wrote #320150:

Sorry, my kids are my exclusive homework furnishers :-)

Just like my house.

And thanks for the hint.

Offline

#8 2019-11-21 13:09:34

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

crib sheet

month-<txp:evaluate query='<txp:php>print date ('m');</txp:php>' />

will be displayed:
month-01
month-02
…………………..
month-11
month-12

<img src="month-<txp:evaluate query='<txp:php>print date ('m');</txp:php>' />.png" >

Last edited by singaz (2019-11-21 13:10:23)


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#9 2019-11-21 13:52:06

etc
Developer
Registered: 2010-11-11
Posts: 5,683
Website GitHub

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

singaz wrote #320179:

<img src="month-<txp:evaluate query='<txp:php>print date ('m');</txp:php>' />.png" >...

Or even

<img src="month-<txp:php>print date ('m');</txp:php>.png" >

but we don’t consider <txp:php /> as “core” solution, right? However, if you register date function in PHP functions enabled in txp:evaluate pref, you will be able to call

<img src="month-<txp:evaluate query="date('m')" />.png" >

Offline

#10 2019-11-21 19:25:46

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

How to register a function for <txp:evaluate/> ?

<txp:php>print date ('m');</txp:php>
or
print date ('m');
or
date ('m');
php

This does not work.

What syntax should be?

Last edited by singaz (2019-11-21 19:32:52)


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#11 2019-11-21 19:32:00

etc
Developer
Registered: 2010-11-11
Posts: 5,683
Website GitHub

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

singaz wrote #320187:

How to register a function for <txp:evaluate/> ?

Like this

Offline

#12 2019-11-21 19:43:54

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

Oh yeah! Here is how it works.

Thanks.

I tried many options here .

But just “data” did not understand.

Everything just worked. It turns out that can register the “time” and change the blocks during the day.

Great opportunities open up.

I love textpattern!

Last edited by singaz (2019-11-21 19:54:49)


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#13 2019-11-21 20:01:17

etc
Developer
Registered: 2010-11-11
Posts: 5,683
Website GitHub

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

singaz wrote #320189:

It turns out that can register the “time” and change the blocks during the day.

I like date_sunrise … but it works unreliably.

Offline

#14 2020-02-26 15:48:48

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

The task is a little harder and I do not know how to do it.

There is an article, a list of names with birthdays:

Name 1, 28.02.2020
Name 2, 01.03.2020
Name 3, 05.03.2020
Name 4, 12.03.2020
Name 5, 04.04.2020
Name 6, 15.04.2020
Name 7, 03.05.2020
Name 8, 09.05.2020

Every month you need to show the names of the people of the birthday.

How to automate?

My way is not working:

<txp:variable name="month" value="<txp:evaluate query='<txp:php>print date ('m');</txp:php>' />" />
or
<txp:variable name="month" value="<txp:evaluate query='date('m')' />" />

<txp:if_variable name="month" value="2">
Name 1, 28.02.2020
</txp:if_variable>
<txp:if_variable name="month" value="3">
Name 2, 01.03.2020
Name 3, 05.03.2020
Name 4, 12.03.2020
</txp:if_variable>

I know about the plugin etc_date. Maybe there is a way to do it without a plugin?

Last edited by singaz (2020-02-26 15:51:50)


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#15 2020-02-26 16:04:46

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,216
Website GitHub

Re: Auto-rotation of the skin layer of themes by dates/season/holidays?

singaz wrote #321923:

The task is a little harder and I do not know how to do it … Maybe there is a way to do it without a plugin?

The PHP manual for the date function says that m = “Numeric representation of a month, with leading zeros” and n = ‘Numeric representation of a month, without leading zeros’ so either:

  • try your tests with 02 or 03, or
  • use: date('n').

You might also want to try if you can skip the variable and go with evaluate (you’ll need to add “date” to the functions permitted for evaluate in Admin › Preferences › Advanced options):

<txp:evaluate query="date('n') == '2'">
Name 1, 28.02.2020
</txp:evaluate>
<txp:evaluate query="date('n') == '3'">
Name 2, 01.03.2020
Name 3, 05.03.2020
Name 4, 12.03.2020
</txp:evaluate>

(untested).


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB