forked from greenpeace/planet4-master-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.php
54 lines (43 loc) · 1.31 KB
/
tag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Displays a Campaign (Tag) page.
*
* Category <-> Issue
* Tag <-> Campaign
* Post <-> Action
*
* @package P4MT
*/
use P4\MasterTheme\Context;
use P4\MasterTheme\Post;
use P4\MasterTheme\ListingPage;
use Timber\Timber;
if (!is_tag()) {
exit();
}
$tag = get_queried_object();
$redirect_id = get_term_meta($tag->term_id, 'redirect_page', true);
if ($redirect_id) {
global $wp_query;
$redirect_page = get_post($redirect_id);
$wp_query->queried_object = $redirect_page;
$wp_query->queried_object_id = $redirect_page->ID;
// Allow modification of redirect page behavior.
do_action('p4_action_tag_page_redirect', $redirect_page);
include 'page.php';
exit();
}
$post = Timber::query_post(false, Post::class); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$context = Timber::get_context();
if ($post instanceof \WP_Post) {
$post = new Post($post->ID);
Context::set_og_meta_fields($context, $post);
}
$context['taxonomy'] = $tag;
$context['tag_name'] = single_tag_title('', false);
$context['tag_description'] = wpautop($tag->description);
// Temporary fix with rewind, cf. https://github.com/WordPress/gutenberg/issues/53593
rewind_posts();
$templates = ['tag.twig', 'archive.twig', 'index.twig'];
$page = new ListingPage($templates, $context);
$page->view();