Dynamic links and webpages

Hello, I would like to know if it is possible to create a page that changes its content according to the hour of the day or the months of the year. Or maybe a link that links to different pages according to the hour/day/month/season.
Really like to develop a project over it.
Thank you

Hello Cerrax,
Yes it’s possible to do that.
Suppose that you want to change a Title from SOON to be AVAILABLE on a specific date
" 1/ June /2018 “. So, you get the currentDate " Check this code snippet to get the date in yyyy/mm/dd format - https://www.wix.com/code/home/forum/questions-answers/date-display-formating " ,
then :
if ( currentDate === 1/ June /2018){
$w(”#title").text = Available;
}

hope this helps you.

Best,
Mustafa

Oh really thank you!

And if I would like to change for example a webpage linked to an image or a text?

Sorry for the question, but I’m not really into web programming…

You welcome,

same as before, just change the hypertext when ever you want a change :

if (condition){
$w(" # Text").html = ‘Stunning web sites’; // change the TEXT to a link/another link
}

no worries at all.
let me know if you have more questions .

Best,
Mustafa.

Thank you Mustafa.
I post here below some rows of code.
I’m having some problems.
I’ve used the snippet for the date and it works but even if the conditions are satisfied, the event doesn’t run.

I’m making some mistakes but I do not know which one…
I’ve also read some guides on the Wix API…I’m learning…but not fast enough…

Thank you in advance

Ok, some updates.

Change the code a little bit and now the condition works and the text change into “Stunning websites”, the link works!

I suppose that I could also add more conditions into one “if” structure (dateStr > “1234” && dateStr > “4321” || dateStr === 4567), am I right?

Another silly question, very basic: when I change the link linked by an hypertext, How can I leave its style unchanged (the font type, dimensions, etc…)?

Thank you again Mustafa :wink:

Yes, you’re right, It’s a regular IF statement that you can add any condition you want.

Regarding to the styling, you can add style to the HTML tag:

 $w("#Text").html = '<a style="color:red;font-size:20px" href="http://wix.com" >Stunning web sites</a>';

So, if you want the style to be the same, just change the Link.

Welcome.

Mustafa

1 Like

How can I change only the link without changing anything about the text (content, style, etc…)?
If I omit the style the text it’s been formatted with a default black arial-like appearance.

When you have your style between the tag and you want it to be the same for any link you change, you only have to copy/paste the code and change the href=“link.com” :

this is the old one:

$w("#Text").html = '<a style="color:red;font-size:20px" href="http://link1.com" >Stunning web sites</a>';

New link with same style :

if( today's date === 30-May-2018) {
$w("#Text").html = '<a style="color:red;font-size:20px" href="http://link2.com" >another website</a>';
} 

Ok, thank you.
I thought there was an option to maintain the same style chosen graphically by the wix standard interface (without coding) and only replace the new link, without specify colour, font and so on on the original text link.

Thank you very much!

In your case, you have to access the element by code because you want to change the like based on date/time. If you want it to be static you can place a BUTTON then customize it style to look like a text without button border/BOX, then you can link it with the URL you want.

Good Luck

Mustafa.

Yes, sure. In the past I’ve done it, but now I have to place some dynamic links.

thank you very much!

You welcome Cerrax.
Good Luck.

Mustafa