(via // img-sizes.twig) AND the preload (base.twig) so imagesizes always // matches the rendered . Breakpoints: <=479, <=575, <=767, <=991, // <=1199, <=1399, else. $data['img_sizes'] = array( 'hero' => array( '120vw', '100vw', '100vw', '100vw', '100vw', '66.6vw', '66.6vw' ), // Obraz wyróżniający na singlach porady/przepisy/skladniki-odzywcze // (components/post-article/post-article.twig). 'article' => array( '84vw', '84vw', '407px', '510px', '615px', '615px', '749px' ), // Główny obraz produktu (sections/product-banner/product-banner.twig). 'product' => array( '86vw', '90vw', '500px', '680px', '364px', '420px', '420px' ), ); $data['theme_url'] = get_template_directory_uri(); if ( is_single() ) { $news = new Timber\PostQuery( array( 'post_type' => 'porady', 'posts_per_page' => 3, 'post__not_in' => array( get_the_ID() ), ) ); } else { $news = new Timber\PostQuery( array( 'post_type' => 'porady', 'posts_per_page' => 3, ) ); } $data['news'] = $news; if ( is_home() ) { $data['post'] = new TimberPost(); $data['posts'] = new Timber\PostQuery(); $template = array( 'blog.twig' ); } elseif ( is_front_page() ) { $data['page'] = new TimberPost(); $template = array( 'home.twig' ); } elseif ( is_page_template() ) { $data['page'] = 'page'; $template_slug = get_page_template_slug(); $template = array( $template_slug . '.template.twig', 'template.twig' ); } elseif ( is_single() ) { $data['post'] = Timber::query_post(); if ( is_singular( 'porady' ) ) { $data['display_author'] = true; } if ( is_singular( 'przepisy' ) ) { $post_term = get_the_terms( $post->ID, 'recipes_category' ); if ( $post_term ) { $data['term_name'] = $post_term[0]->name; $other_recipes = new Timber\PostQuery( array( 'post_type' => 'przepisy', 'posts_per_page' => 3, 'post__not_in' => array( get_the_ID() ), 'tax_query' => array( array( 'taxonomy' => $post_term[0]->taxonomy, 'field' => 'slug', 'terms' => $post_term[0]->slug, ), ), ) ); $data['other_recipes'] = $other_recipes; } } $template = array( 'blog-post-' . $post->ID . '.twig', 'blog-post-' . $post->post_type . '.twig', 'blog-post.twig', ); } elseif ( is_page() ) { $data['page'] = 'page'; $data['post'] = new TimberPost(); $data['pageName'] = $post->post_title; $template = array( 'page-' . $post->post_name . '.twig', 'page.twig' ); } elseif ( is_category() ) { $data['term'] = new Timber\Term(); $data['queried_object'] = get_queried_object(); $template = array( 'archive-' . get_query_var( 'tag_id' ) . '.twig', 'archive.twig' ); } elseif ( is_tag() ) { $data['term'] = new Timber\Term(); $data['page'] = 'archive'; $data['queried_object'] = get_queried_object(); $template = array( 'archive-' . get_query_var( 'tag_id' ) . '.twig', 'tag.twig' ); } elseif ( is_author() ) { $author_id = get_the_author_meta( 'ID' ); $data['author'] = new Timber\User( $author_id ); $data['author']->fields = get_fields( 'user_' . $author_id ); $data['page'] = 'archive'; $template = array( 'archive-' . get_queried_object()->name . '.twig', 'author.twig' ); } elseif ( is_search() ) { $data['query_phrase'] = esc_html( get_search_query() ); $data['page'] = 'archive'; $data['posts'] = new Timber\PostQuery(); $data['pagination'] = $data['posts']->pagination( 30 ); $template = array( 'search.twig' ); } elseif ( is_archive() ) { $data['page'] = 'archive'; $data['options'] = get_fields( 'options' ); $data['queried_object'] = get_queried_object(); $data['pageName'] = post_type_archive_title( '', false ); $data['categories_products'] = get_field( 'product_categories', 'options' ); $data['pagination'] = $data['posts']->pagination( 3 ); $data['term_forkids'] = Timber::get_terms( 'for_kids_category' ); $data['sorting'] = get_field('sorting',$data['queried_object']); if(isset($_GET['order'])){ if($_GET['order'] == 'custom'){ $priority_posts = array_column($data['sorting'],'ID') ; $priority_posts_loop = new Timber\PostQuery( array( 'post__in' => $priority_posts, 'post_type' => 'produkty', 'orderby' => 'post__in' ) ); $data['posts'] = $priority_posts_loop; $data['paged'] = $paged; } } if ( get_field( 'przepisy_categories', 'options' ) ) { foreach ( get_field( 'przepisy_categories', 'options' ) as $key => $val ) { $data['recipes_categories'][] = new Timber\Term( $val ); } } if ( get_field( 'porady_categories', 'options' ) ) { foreach ( get_field( 'porady_categories', 'options' ) as $key => $val ) { $data['advice_categories'][] = new Timber\Term( $val ); } } if ( get_field( 'dla_twojego_dziecka_categories', 'options' ) ) { foreach ( get_field( 'dla_twojego_dziecka_categories', 'options' ) as $key => $val ) { $data['for_kids_categories'][] = new Timber\Term( $val ); } } if ( get_field( 'materialy_do_pobrania_categories', 'options' ) ) { foreach ( get_field( 'materialy_do_pobrania_categories', 'options' ) as $key => $val ) { $data['materialy_do_pobrania_categories'][] = new Timber\Term( $val ); } } $args = array( 'post_type' => 'skladniki-odzywcze', 'post_status' => 'publish', 'posts_per_page' => - 1, 'orderby' => 'title', 'order' => 'ASC', ); $data['skladniki'] = Timber::get_posts( $args ); if ( is_tax() ) { $term_id = $data['queried_object']->term_id; $custom_tax_name = $data['queried_object']->taxonomy; $data['term'] = new Timber\Term(); if ( is_tax( 'product_category' ) ) { $template = array( 'archive-produkty.twig', 'archive.twig', ); } if ( is_tax( 'recipes_category' ) ) { $template = array( 'archive-przepisy.twig', 'archive.twig', ); } if ( is_tax( 'porady_category' ) ) { $template = array( 'archive-porady.twig', 'archive.twig', ); } if ( is_tax( 'for_kids_category' ) ) { $template = array( 'archive-dla-twojego-dziecka.twig', ); } if ( is_tax( 'to_download_category' ) ) { $template = array( 'archive-do-pobrania.twig', ); } // Taksonomie bez wlasnej galezi wyzej (recipes_tags, jadlospis_category) // zostawialy $template niezdefiniowane, przez co Timber::render() // wypisywal zrodlo tego pliku zamiast HTML-a. Kolejnosc fallbacku: // szablon taksonomii -> szablon archiwum jej typu tresci -> archive.twig. if ( ! isset( $template ) ) { $fallback_templates = array( 'archive-' . $custom_tax_name . '.twig' ); $tax_object = get_taxonomy( $custom_tax_name ); if ( $tax_object ) { foreach ( (array) $tax_object->object_type as $tax_post_type ) { $fallback_templates[] = 'archive-' . $tax_post_type . '.twig'; } } $fallback_templates[] = 'archive.twig'; $template = $fallback_templates; } } else { $template = array( 'archive-' . get_queried_object()->query_var . '.twig', 'archive.twig', ); } // Client-side sort (see src/js/components/sort-posts.js) needs the FULL, // pre-rendered post set embedded as JSON. Production is a static export // (Simply Static strips query strings before saving pages — confirmed via // class-ss-util.php::remove_params_and_fragment()), so a server-side // re-query on ?order=... can never happen at request time; this must run // unconditionally (not gated on $_GET) so the JSON is always baked in. $sort_post_type = null; if ( is_tax( 'porady_category' ) ) { $sort_post_type = 'porady'; } elseif ( is_tax( 'recipes_category' ) ) { $sort_post_type = 'przepisy'; } elseif ( is_tax( 'product_category' ) ) { $sort_post_type = 'produkty'; } elseif ( in_array( $data['queried_object']->query_var ?? null, array( 'porady', 'przepisy', 'produkty' ), true ) ) { $sort_post_type = $data['queried_object']->query_var; } if ( $sort_post_type ) { // Identical content is rebuilt on EVERY paginated page of the same // archive/term (page/1, page/2, ...) — without caching, this repeats // ~15-77x Timber::compile() calls per page, which was slow enough to // make Simply Static's crawler silently drop/timeout on some paginated // URLs during export (they then got deleted from the static output as // "no longer found"). Cache the expensive part per post-type+term. $sort_cache_key = 'naturell_sort_json_' . $sort_post_type . '_' . ( is_tax() ? $term_id : 'all' ); $sort_entries = get_transient( $sort_cache_key ); if ( false === $sort_entries ) { $sort_query_args = array( 'post_type' => $sort_post_type, 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', ); if ( is_tax() ) { $sort_query_args['tax_query'] = array( array( 'taxonomy' => $custom_tax_name, 'field' => 'term_id', 'terms' => $term_id, ), ); } $sort_card_templates = array( 'porady' => 'components/short-article-view/short-article-view.twig', 'przepisy' => 'components/list-diet-item/list-diet-item.twig', 'produkty' => 'components/short-product-view/short-product-view.twig', ); $sort_card_template = $sort_card_templates[ $sort_post_type ]; $sort_entries = array(); foreach ( new Timber\PostQuery( $sort_query_args ) as $sort_post ) { $sort_card_html = Timber::compile( $sort_card_template, array( 'item' => $sort_post ) ); // archive-przepisy.twig wraps each card in .archive-diet__item — // reproduce that wrapper so the swapped-in HTML matches exactly. if ( 'przepisy' === $sort_post_type ) { $sort_card_html = '
' . $sort_card_html . '
'; } $sort_entries[] = array( 'date' => $sort_post->post_date, 'html' => $sort_card_html, ); } set_transient( $sort_cache_key, $sort_entries, HOUR_IN_SECONDS ); } // JSON_HEX_TAG: guards against a stray "" inside rendered card // HTML prematurely closing the