| | |
| | | <?php |
| | | // /content/progress.php |
| | | use JVBase\meta\MetaManager; |
| | | |
| | | function altr_progress():array |
| | | { |
| | | return [ |
| | |
| | | 'label' => 'Progression', |
| | | ] |
| | | ], |
| | | 'seo' => [ |
| | | 'schema' => [ |
| | | 'type' => 'BeforeAfter', |
| | | 'name' => '{{post_title}}', |
| | | 'description' => '{{post_excerpt}}', |
| | | 'about' => ['@id' => '{{site_url}}/#laser-removal-service'], |
| | | 'temporalCoverage' => '{{post_date}}/{{last_date}}', |
| | | 'additionalProperty' => [ |
| | | ['name' => 'Number of sessions', 'value' => '{{number.name}}'], |
| | | ['name' => 'Treatment area', 'value' => '{{body-part.name}}'], |
| | | ], |
| | | 'associatedMedia' => '{{timeline_photos}}', // parent post thumbnail = before; each child post has a post thumbnail, too |
| | | ], |
| | | 'meta' => [ |
| | | 'title' => '{{body-part.name}} Laser Tattoo Removal – Before & After', |
| | | 'description' => 'Documented progress of {{body-part.name}} laser tattoo removal over {{number.name}} sessions.', |
| | | ], |
| | | 'archive' => [ |
| | | 'type' => 'CollectionPage', |
| | | 'name' => 'Tattoos Before and After Laser Tattoo Removal', |
| | | ], |
| | | ], |
| | | 'feed' => [ |
| | | 'single' => [ |
| | | 'pre_title' => 'Before & After Laser Tattoo Removal', |
| | | ], |
| | | 'archive' => [ |
| | | |
| | | ], |
| | | 'config' => [ |
| | | 'is_gallery' => false, |
| | | 'content' => 'progress', |
| | | 'context' => 'progress', |
| | | 'id' => [], |
| | | 'class' => [], |
| | | ] |
| | | ], |
| | | 'fields' => [ |
| | | 'post_title' => [ |
| | | 'type' => 'text', |
| | |
| | | 'post_status' => [ |
| | | 'type' => 'radio', |
| | | 'label' => 'Status', |
| | | 'hidden' => true, |
| | | 'options' => [ |
| | | 'publish' => 'Show', |
| | | 'draft' => 'Hide', |
| | |
| | | 'section' => 'progression', |
| | | 'for_all' => true, |
| | | ], |
| | | 'post_date' => [ |
| | | 'type' => 'date', |
| | | 'label' => 'Date', |
| | | 'for_all' => true, |
| | | ], |
| | | 'post_thumbnail' => [ |
| | | 'type' => 'image', |
| | | 'type' => 'upload', |
| | | 'label' => 'Image', |
| | | 'quickEdit' => true, |
| | | 'section' => 'progression', |
| | |
| | | 'createNew' => true, |
| | | 'section' => 'progression' |
| | | ], |
| | | 'number' => [ |
| | | 'type' => 'taxonomy', |
| | | 'taxonomy' => 'number', |
| | | 'autocomplete' => true, |
| | | 'label' => 'Number of Treatments', |
| | | 'quickEdit' => true, |
| | | 'createNew' => true, |
| | | 'section' => 'progression' |
| | | ], |
| | | 'post_content' => [ |
| | | 'type' => 'textarea', |
| | | 'quill' => true, |
| | |
| | | 'upload_title' => 'Upload Before & Afters', |
| | | ]; |
| | | } |
| | | |
| | | add_filter('jvbFeedItem', 'altr_progress_item', 10, 2); |
| | | |
| | | function altr_progress_item(string $out, array $config):string |
| | | { |
| | | if (!in_array('progress', $config['content'])) { |
| | | return $out; |
| | | } |
| | | |
| | | ob_start(); |
| | | ?> |
| | | <details class="item feed col a-start" data-timeline> |
| | | <summary> |
| | | <a> |
| | | <span>Before</span> |
| | | <img width="300px" height="300px" loading="lazy" decoding="async" class="before"> |
| | | <img width="300px" height="300px" loading="lazy" decoding="async" class="after"> |
| | | <span>After</span> |
| | | </a> |
| | | </summary> |
| | | <div class="more"> |
| | | <p class="started">Started:<time></time></p> |
| | | <p class="updated">Last treated:<time></time></p> |
| | | <p class="total">Total Treatments: <b></b></p> |
| | | <ul class="term-list"><li><a></a></li></ul> |
| | | </div> |
| | | </details> |
| | | <?php |
| | | return ob_get_clean(); |
| | | } |
| | | |
| | | |
| | | add_filter('jvbCoreFeaturedImage', 'altr_progress_featured_image', 10, 2); |
| | | function altr_progress_featured_image(string $out, string $postType):string |
| | | { |
| | | if ($postType !== BASE.'progress') { |
| | | return $out; |
| | | } |
| | | $route = JVB()->routes('content'); |
| | | |
| | | global $post; |
| | | $data = $route->formatTimeline($post); |
| | | $timeline = $data['fields']['timeline']; |
| | | $total = count($timeline); |
| | | if ($total === 1) { |
| | | return $out; |
| | | } |
| | | |
| | | $total--; |
| | | $first = '<span class="before">Before</span>'.jvbFormatImage($timeline[0]['post_thumbnail'],'tiny','medium',false); |
| | | $last = '<span class="after">After '.$total.' Tx</span>'.jvbFormatImage($timeline[$total]['post_thumbnail'],'tiny','medium',false); |
| | | return $first.$last; |
| | | } |
| | | |
| | | |
| | | add_filter('jvbSEOResolveVariable', 'altr_progress_variables', 10, 6); |
| | | function altr_progress_variables(mixed $return, string $variable, ?int $ID, ?string $objectType, ?string $contentType, ?MetaManager $meta):mixed |
| | | { |
| | | if ($contentType !== 'progress' || !in_array($variable, ['timeline_photos', 'last_date'])) { |
| | | return $return; |
| | | } |
| | | |
| | | $children = get_children([ |
| | | 'post_parent' => $ID, |
| | | 'post_status' => 'publish', |
| | | 'order_by' => 'date', |
| | | 'fields' => 'ids' |
| | | ]); |
| | | //Insert the parent to the beginning |
| | | array_unshift($children, $ID); |
| | | if ($variable === 'timeline_photos') { |
| | | return array_map(function ($item) { |
| | | return get_post_thumbnail_id($item); |
| | | }, $children); |
| | | } |
| | | // $variable === 'last_date' |
| | | return get_the_date('c', $children[array_key_last($children)]); |
| | | } |