Skip to content

Commit

Permalink
PLANET-6793: Sitemap native taxonomies (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
lithrel authored Aug 29, 2023
1 parent 4fe6d37 commit 6c1e1b0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
13 changes: 13 additions & 0 deletions assets/src/scss/pages/_sitemap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@
h5 {
margin-bottom: 1rem;
}

ul {
list-style: none;
padding-inline-start: 0;
@include small-and-less {
margin-bottom: 0;
}

li {
font-size: inherit;
line-height: inherit;
}
}
}
41 changes: 29 additions & 12 deletions page-templates/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,40 @@

$context = Timber::get_context();
$post = new Post(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$sitemap = new Sitemap();
$page_meta_data = get_post_meta($post->ID);

$context['post'] = $post;
$context['header_title'] = is_front_page() ? '' : ( $page_meta_data['p4_title'][0] ?? $post->title );
$context['header_title'] = is_front_page() ? '' : ($page_meta_data['p4_title'][0] ?? $post->title);
$context['background_image'] = wp_get_attachment_url(get_post_meta(get_the_ID(), 'background_image_id', 1));
$context['custom_body_classes'] = 'white-bg';
$context['page_category'] = 'Sitemap Page';

$context['actions_title'] = __('Act', 'planet4-master-theme');
$context['issues_title'] = __('Explore', 'planet4-master-theme');
$context['evergreen_title'] = __('About Greenpeace', 'planet4-master-theme');
$context['page_types_title'] = __('Articles', 'planet4-master-theme');
if (get_theme_mod('new_identity_styles')) {
$context['categories'] = get_categories(['orderby' => 'name', 'order' => 'ASC']);
$context['posts'] = [];
foreach ($context['categories'] as $cat) {
if ($cat->slug === 'uncategorized') {
continue;
}
$context['posts'][$cat->term_id] = get_posts([
'post_type' => 'page',
'category' => $cat->term_id,
'orderby' => 'title',
'order' => 'ASC',
]);
}
} else {
$sitemap = new Sitemap();

$context['actions'] = $sitemap->get_actions();
$context['issues'] = $sitemap->get_issues();
$context['evergreen_pages'] = $sitemap->get_evergreen_pages();
$context['page_types'] = $sitemap->get_page_types();
$context['page_category'] = 'Sitemap Page';
$context['actions_title'] = __('Act', 'planet4-master-theme');
$context['issues_title'] = __('Explore', 'planet4-master-theme');
$context['evergreen_title'] = __('About Greenpeace', 'planet4-master-theme');
$context['page_types_title'] = __('Articles', 'planet4-master-theme');

$context['actions'] = $sitemap->get_actions();
$context['issues'] = $sitemap->get_issues();
$context['evergreen_pages'] = $sitemap->get_evergreen_pages();
$context['page_types'] = $sitemap->get_page_types();
}

Timber::render([ 'sitemap.twig' ], $context);
Timber::render(['sitemap.twig'], $context);
16 changes: 16 additions & 0 deletions templates/sitemap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@
<br/>
</div>
{% endif %}
{% if categories %}
{% for cat in categories %}
<div class="col-md-5 order-md-2 order-lg-3 col-lg-3">
{% if posts[cat.term_id] is not empty %}
<h5 class="mb-3 mt-5 mt-lg-0">
<a href="{{ function('get_permalink', cat.term_id) }}">{{ cat.name }}</a>
</h5>
<ul>
{% for post in posts[cat.term_id] %}
<li><a href="{{ post.url }}">{{ post.post_title }}</a></li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endfor %}
{% endif %}
</div>
</div>
</div>
Expand Down

0 comments on commit 6c1e1b0

Please sign in to comment.