Skip Navigation

[Resolved] Make a view only appear on specific days

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show a View on my site only on specific days of the week. The View should only appear Monday - Thursday.

Solution:
There is no built-in way to accomplish this, but you can use a custom shortcode to return the day of the week and test that value in a conditional. Add this code to functions.php:

add_shortcode( 'format_today', 'format_today_func');
function format_today_func($atts = [])
{
  $atts = shortcode_atts([
    'format' => 'l',
  ], $atts);
  $today = date($atts['format']);
  return $today;
}

Then go to Toolset > Settings > Frontend Content > Third-party shortcode arguments and add format_today.

The full conditional:

[wpv-conditional if="( '[format_today]' eq 'Friday' ) OR ( '[format_today]' eq 'Saturday' ) OR ( '[format_today]' eq 'Sunday' )" evaluate="false"]
View goes here and is shown Monday - Thursday only.
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://codex.wordpress.org/Shortcode_API

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by tomS-10 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#906035

I wonder if it`s possible to make a view only to appear on specific days.

We have a view that shows most read articles in the current week. Each friday, saturday and sunday we want this view to be shown on the front page. Since it`s most read articles in the current week, there are no use of the function monday-friday.

Is there a way to do this?

#906219

There's no built-in way for Toolset conditionals to respond to the current date, but you could add a custom shortcode that returns the current day of the week and test that value. Here's a custom shortcode that returns the day of the week as a string like "Monday", "Tuesday", "Wednesday", etc. Add this code to your child theme's functions.php file:

add_shortcode( 'format_today', 'format_today_func');
function format_today_func($atts = [])
{
  $atts = shortcode_atts([
    'format' => 'l',
  ], $atts);
  $today = date($atts['format']);
  return $today;
}

Then go to Toolset > Settings > Frontend Content > Third-party shortcode arguments and add format_today.

After you register the shortcode in third-party shortcode arguments you can use it in a conditional. Here's some more information about conditionals:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Let me know if you have additional questions about this.

#906623

Thank you Christian. Very easy and quick solution.

Problem solved by adding the following inside [wpv-items-found]

[wpv-conditional if="( '[format_today]' eq 'Friday' ) OR ( '[format_today]' eq 'Saturday' ) OR ( '[format_today]' eq 'Sunday' )"]