Title: Dynamically generating a structure
Last modified: April 29, 2023

---

# Dynamically generating a structure

 *  [sanumolu5](https://wordpress.org/support/users/sanumolu5/)
 * (@sanumolu5)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-generating-a-structure/)
 * I have a page where the details of online classes are statically shown per weekday(
   please refer to the screenshot).
 * [https://www.awesomescreenshot.com/image/39387439?key=93f54ecd2c0ed4fa40e35eb89f94bbcb](https://www.awesomescreenshot.com/image/39387439?key=93f54ecd2c0ed4fa40e35eb89f94bbcb)
 * If you see there are weekdays tabs (sunday, monday,…). The content shown under
   each weekday tab is one template each. The template is created in Elementor using
   widgets like Header, Image, Text-editor, Shortcode for each online class. And
   all the classes are formatted with the help of section and columns that “Edit
   with Elementor” provides.
 * Now I want to make this whole content under every tab a dynamic one. Because 
   there is time shown for every class, that too based upon the user’s timezone,
   few classes in the evening (as per CDT) on one particular weekday may fall on
   the next day morning in some other timezone. So, for that reason and also to 
   be called a professional developer (instead of a dumb developer), I want to make
   this whole page dynamically generated.
 * Please provide pointers on how can I do this. I couldn’t find proper code or 
   approach on Google anywhere. It would be very great if you could provide the 
   steps and a sample code that I could use to develop my requirement. Thank you.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdynamically-generating-a-structure%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-generating-a-structure/#post-16697690)
 * You’d probably be best off using a custom template for the entire page. Use the
   usual tab technique of hiding or showing content based on which day was clicked.
 * You can query for posts which fall within any arbitrary date/time range with 
   the “date_query” arg. To get the posts for any particular day of the week, you’d
   need to convert the date/time range for that particular day in the user’s timezone
   into an equivalent GMT date/time range with which you can query posts with.
 *  Thread Starter [sanumolu5](https://wordpress.org/support/users/sanumolu5/)
 * (@sanumolu5)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-generating-a-structure/#post-16697705)
 * Hi [@bcworkz](https://wordpress.org/support/users/bcworkz/) ,
 * Thank you very much for the reply.
    1. When you suggested custom template for the entire page, what does that mean?
       I will be having different number of classes on each day. So without having 
       to create custom template for each day, will I be able to generate online classes
       with just one custom template?
    2. And how can I generate that structure for each class recursively (per day)?
    3. Also I want to let you know that few classes repeat on multiple days. Few classes
       on all days. Few classes only once per week.
 *  -  This reply was modified 3 years, 1 month ago by [sanumolu5](https://wordpress.org/support/users/sanumolu5/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-generating-a-structure/#post-16699068)
 * “Template” has become rather ambiguous. To be clear, I’m referring to a classic
   theme .php template named according to [template hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/#single-page).
   If you have a newer block theme, I think this would be more akin to a custom 
   pattern. All days can be generated from this one file. [JavaScript and CSS manage](https://www.w3schools.com/howto/howto_js_tabs.asp)
   which day is visible.
 * Once you have the user’s timezone offset, your code would determine what GMT 
   date/times span that particular day. `strtotime()` will convert most textual 
   date strings into a Unix timestamp. Adjust as necessary to get the equivalent
   GMT date/times. Then you can query for any classes whose times fall within that
   range. I mentioned “date_query”, but that would be for a post’s published date.
   If the date/times you need to query for are saved in post meta, you’d be using“
   meta_query” instead.
 * Whether such a query will find classes occurring on multiple days depends on 
   how their times are saved. “Every Tuesday and Thursday” doesn’t work well. “2023-
   05-16 15:00, 2023-05-18 15:00” works better. Each class time as a separate meta
   field, preferably as a Unix timestamp, would be ideal from a query standpoint,
   but really any consistently logical scheme can be accommodated since you’re custom
   coding everything.
 * This isn’t literally a re-entrant recursive process where a function calls itself,
   it’s really just a couple of nested loops. Over simplified, but like this:
 *     ```
       $days = ['Monday','Wednesday','Friday'];
       foreach ( $days as $day ) {
          //query for $classes on $day
          foreach ( $classes as $class ) {
             // output $class
          }
       }
       ```
   
 * The complexity comes from coming up with the correct date/time span for each 
   day, and how that can be used to query for classes within each span.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Dynamically generating a structure’ is closed to new replies.

## Tags

 * [html](https://wordpress.org/support/topic-tag/html/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/dynamically-generating-a-structure/#post-16699068)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
