I am trying to: I need to show the hour of an article only if the hour in the date field is set to a specicif hour (ex. 08:45) and hide the hour in the frontend when the hour is not set (ex. 00:00)
So when an article have only a date, I want to show this date in frontend, when an article have the date and the hour, I want to show both
I visited this URL:
I expected to see:
Instead, I got:
Hello, I'd like to make sure I understand you correctly. You said you want to show the hour on the front end "only if the hour in the date field is set to a specific hour." You also said you want to show the hour on the front end "if is set different of 00:00". These are different rules, and the difference is important, so I need some clarification.
If you look at the date and time inputs, 00:00 is a specific hour, and it is not possible to select an option without a specific hour or a specific minute. In other words, a date with time field will always have a specific hour and will always have a specific minute, even if that is "00".
With that in mind, do you want to test if the hour or minute is something other than 00, or do you want to test if the user has not selected something for hour or minute?
Ok I'm thinking for a workaround.
If I create two separate fields, the first for the date only (I see it's possible to set this) and on other two select field one with hour, one with minutes.
So In view I've added this code: [types field="date" style="text" format="j F Y"][/types] - [types field="hour"][/types]:[types field="minutes"][/types]
In frontend the output correctly shows the minutes only in articles with this fields set, but I see still the " - " and ":" carachters between the hour e minutes fields.
Now I need only a way to put the " - " and ":" in types field hour or minutes for show only when necessary
I hope you understand my needs, If you look this page hidden link
you see the output page, you see the " - " and ":" carachters also in the articles wit non hour, minutes settings.
thanks in advance, Aldo
Okay, you'll need to use conditional output that tests the value of hour and minutes. If hour AND minutes do not equal an empty string, you will show the content. Here's an example of a conditional that tests custom fields "hour" and "minutes":
[types field="date" style="text" format="j F Y"][/types]
[wpv-conditional if="( $(wpcf-hour) ne '' ) AND ( $(wpcf-minutes) ne '' )"]
- [types field='hours'][/types]:[types field='minutes'][/types]
[/wpv-conditional]
Some more information on conditional output here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
GREAT!!! now the output in frontend works wery well..
tnx again Christian