Skip to content

Commit 0836393

Browse files
authored
Merge pull request #200 from devgeniem/TMS-1173
TMS-1173: Add hero-layout for blog-article archive & blog-category taxonomy archive
2 parents fd99c5f + d024f41 commit 0836393

File tree

5 files changed

+199
-33
lines changed

5 files changed

+199
-33
lines changed

CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
- TMS-1173:
11+
- Add hero-image field for blog-category taxonomy
12+
- Add hero-layout for blog-article archive & blog-category taxonomy archive
13+
1014
## [1.9.7] - 2025-08-11
1115

1216
- TMS-1174: Change icon colors to improve accessibility

lib/ACF/BlogCategoryGroup.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
namespace TMS\Theme\Tredu\ACF;
3+
4+
use Geniem\ACF\Exception;
5+
use Geniem\ACF\Group;
6+
use Geniem\ACF\RuleGroup;
7+
use Geniem\ACF\Field;
8+
use TMS\Theme\Tredu\Logger;
9+
10+
/**
11+
* Class BlogCategoryGroup
12+
*
13+
* @package TMS\Theme\Tredu\ACF
14+
*/
15+
class BlogCategoryGroup {
16+
17+
/**
18+
* BlogCategoryGroup constructor.
19+
*/
20+
public function __construct() {
21+
\add_action(
22+
'init',
23+
\Closure::fromCallable( [ $this, 'register_fields' ] )
24+
);
25+
}
26+
27+
/**
28+
* Register fields for blog-category taxonomy.
29+
*/
30+
protected function register_fields() : void {
31+
try {
32+
$field_group = ( new Group( 'Blogikategoria' ) )
33+
->set_key( 'fg_blog_category_fields' );
34+
35+
$rule_group = ( new RuleGroup() )
36+
->add_rule( 'taxonomy', '==', 'blog-category' );
37+
38+
$field_group
39+
->add_rule_group( $rule_group )
40+
->set_position( 'normal' );
41+
42+
$field_group->add_fields(
43+
\apply_filters(
44+
'tms/acf/group/' . $field_group->get_key() . '/fields',
45+
[
46+
$this->get_image_field( $field_group->get_key() ),
47+
]
48+
)
49+
);
50+
51+
$field_group = \apply_filters(
52+
'tms/acf/group/' . $field_group->get_key(),
53+
$field_group
54+
);
55+
56+
$field_group->register();
57+
}
58+
catch ( Exception $e ) {
59+
( new Logger() )->error( $e->getMessage(), $e->getTraceAsString() );
60+
}
61+
}
62+
63+
/**
64+
* Get image field.
65+
*
66+
* @param string $key Field group key.
67+
*
68+
* @return Field\Image
69+
* @throws Exception In case of invalid option.
70+
*/
71+
protected function get_image_field( string $key ) : Field\Image {
72+
$strings = [
73+
'image' => [
74+
'title' => \_x( 'Kuva', 'theme ACF', 'tms-theme-tredu' ),
75+
'instructions' => 'Kuvaa käytetään kategorian listaus-sivulla hero-kuvana',
76+
],
77+
];
78+
79+
return ( new Field\Image( $strings['image']['title'] ) )
80+
->set_key( "{$key}_image" )
81+
->set_name( 'image' )
82+
->set_instructions( $strings['image']['instructions'] );
83+
}
84+
}
85+
86+
( new BlogCategoryGroup() );

models/archive.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Archive extends Home {
1515
/**
1616
* Hooks
1717
*/
18-
public static function hooks() : void {
18+
public static function hooks(): void {
1919
add_action(
2020
'pre_get_posts',
2121
[ __CLASS__, 'modify_query' ]
@@ -27,7 +27,7 @@ public static function hooks() : void {
2727
*
2828
* @return int|null
2929
*/
30-
protected static function get_filter_category() : ?int {
30+
protected static function get_filter_category(): ?int {
3131
return is_tax() || is_category()
3232
? get_queried_object_id()
3333
: null;
@@ -40,7 +40,7 @@ protected static function get_filter_category() : ?int {
4040
*
4141
* @return void
4242
*/
43-
public static function modify_query( WP_Query $wp_query ) : void {
43+
public static function modify_query( WP_Query $wp_query ): void {
4444
if ( is_admin() || ( ! $wp_query->is_main_query() || ! $wp_query->is_archive() ) ) {
4545
return;
4646
}
@@ -57,8 +57,33 @@ public static function modify_query( WP_Query $wp_query ) : void {
5757
*
5858
* @return string|null
5959
*/
60-
public function page_title() : ?string {
61-
return single_term_title( '', false );
60+
public function page_title(): ?string {
61+
return \single_term_title( '', false );
62+
}
63+
64+
/**
65+
* Get the page description.
66+
*
67+
* @return string|null
68+
*/
69+
public function page_description(): ?string {
70+
return \term_description( \get_queried_object() );
71+
}
72+
73+
/**
74+
* Get the blog-category image.
75+
*
76+
* @return int|null
77+
*/
78+
public function blog_category_image(): ?int {
79+
$queried_object = \get_queried_object();
80+
$image_field = \get_field( 'image', $queried_object );
81+
82+
if ( ! $image_field ) {
83+
return null;
84+
}
85+
86+
return $image_field['ID'];
6287
}
6388

6489
/**
@@ -75,7 +100,7 @@ public function highlight() : ?object {
75100
*
76101
* @return array
77102
*/
78-
protected function get_filter_categories() : array {
103+
protected function get_filter_categories(): array {
79104
$queried_object = get_queried_object();
80105
$taxonomy = '';
81106

partials/archive-blog-article.dust

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,56 @@
33
{<content}
44
<main class="main-content pb-8" id="main-content">
55
{#ArchiveBlogArticle}
6+
{?page_logo}
7+
<section class="page__hero section has-text-centered is-relative pt-0 pb-0 has-background-cover" {@inlinebg id=page_logo size="fullhd" /}>
8+
<div class="overlay overlay--dark-50"></div>
9+
<div class="is-absolute has-top-50 has-right-0 has-left-0 has-transform-y--50 is-clipped">
10+
<div class="container">
11+
<div class="columns">
12+
<div class="column is-8 is-offset-2">
13+
{?page_title}
14+
<h1 class="mt-0 mb-8 has-text-white">
15+
{page_title|html}
16+
</h1>
17+
{/page_title}
18+
19+
{?page_subtitle}
20+
<p class="mb-0 has-text-white">
21+
{page_subtitle|html}
22+
</p>
23+
{/page_subtitle}
24+
</div>
25+
</div>
26+
</div>
27+
</div>
28+
</section>
29+
{/page_logo}
630
<section class="section">
731
<div class="container">
832
<div class="columns">
9-
{?page_logo}
10-
<div class="column is-2 has-text-centered-mobile">
11-
{@image id=page_logo size="thumbnail" /}
12-
</div>
13-
{/page_logo}
14-
15-
<div class="column is-8 has-text-centered {^page_logo}is-offset-2{/page_logo}">
16-
{?page_title}
17-
<h1 class="mt-0 mb-8">
18-
{page_title|s}
19-
</h1>
20-
{/page_title}
33+
<div class="column is-8 is-offset-2 has-text-centered">
34+
{^page_logo}
35+
{?page_title}
36+
<h1 class="mt-0 mb-8">
37+
{page_title|html}
38+
</h1>
39+
{/page_title}
2140

22-
{?page_subtitle}
23-
<p class="mb-6">
24-
{page_subtitle|s}
25-
</p>
26-
{/page_subtitle}
41+
{?page_subtitle}
42+
<p class="mb-6">
43+
{page_subtitle|html}
44+
</p>
45+
{/page_subtitle}
46+
{/page_logo}
2747

2848
{?page_description}
2949
<div class="container">
3050
<div class="columns">
31-
<div class="column is-10 is-offset-1">
51+
<div class="column">
3252
{>"ui/button-toggle" class="mb-5" text=Strings.s.blog_article.toggle_details target="js-archive-description-toggle-target" /}
3353

3454
<p id="js-archive-description-toggle-target"
35-
class="is-hidden has-text-left">{page_description|s}</p>
55+
class="is-hidden has-text-left">{page_description|html}</p>
3656
</div>
3757
</div>
3858
</div>
@@ -52,7 +72,7 @@
5272
{:else}
5373
<div class="column">
5474
<div class="pt-6 pb-6 h4 has-text-centered">
55-
{Strings.s.home.no_results|s}
75+
{Strings.s.home.no_results|html}
5676
</div>
5777
</div>
5878
{/articles}

partials/archive-inner.dust

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
1+
{?blog_category_image}
2+
<section class="page__hero section has-text-centered is-relative pt-0 pb-0 has-background-cover" {@inlinebg id=blog_category_image size="fullhd" /}>
3+
<div class="overlay overlay--dark-50"></div>
4+
<div class="is-absolute has-top-50 has-right-0 has-left-0 has-transform-y--50 is-clipped">
5+
<div class="container">
6+
<div class="columns">
7+
<div class="column is-8 is-offset-2">
8+
{?page_title}
9+
<h1 class="mt-0 mb-8 has-text-white">
10+
{page_title|html}
11+
</h1>
12+
{/page_title}
13+
14+
{?page_description}
15+
<div class="mb-0 has-text-white">
16+
{page_description|kses}
17+
</div>
18+
{/page_description}
19+
</div>
20+
</div>
21+
</div>
22+
</div>
23+
</section>
24+
{/blog_category_image}
25+
126
<section class="section">
227
<div class="container">
3-
<div class="columns">
4-
<div class="column has-text-centered">
5-
<h1 class="mt-0 mb-8">
6-
{page_title|s}
7-
</h1>
28+
{^blog_category_image}
29+
<div class="columns">
30+
<div class="column has-text-centered">
31+
<h1 class="mt-0 mb-8">
32+
{page_title|html}
33+
</h1>
34+
35+
{?page_description}
36+
{page_description|kses}
37+
{/page_description}
38+
</div>
839
</div>
9-
</div>
40+
{/blog_category_image}
1041

1142
{>"views/home/home-highlight" category_link_classes="is-primary-invert is-borderless" /}
1243

@@ -20,7 +51,7 @@
2051
{:else}
2152
<div class="column">
2253
<div class="pt-6 pb-6 h4 has-text-centered">
23-
{Strings.s.home.no_results|s}
54+
{Strings.s.home.no_results|html}
2455
</div>
2556
</div>
2657
{/articles}

0 commit comments

Comments
 (0)