feat(topics): restore topic taxonomy workflow
This commit is contained in:
1 parent
f3dd1ec3b1
commit
a254cbd3e9
59 files changed
+771
-192
No files matched your search
@@ -96,6 +96,12 @@ $categories = array_map(
|
||||
\Jio\Core\SubmitCategories::tree($settings)
|
||||
);
|
||||
$current_cats = $edit_post ? wp_get_post_categories($edit_post->ID) : [];
|
||||
$topics = array_map(
|
||||
static fn(array $node): \WP_Term => $node['term'],
|
||||
\Jio\Core\SubmitTopics::tree($settings)
|
||||
);
|
||||
$current_topics = $edit_post ? wp_get_post_terms($edit_post->ID, 'topics', ['fields' => 'ids']) : [];
|
||||
$current_topics = is_array($current_topics) ? array_map('intval', $current_topics) : [];
|
||||
|
||||
$custom_dimensions = [];
|
||||
$current_cf = [];
|
||||
@@ -181,6 +187,8 @@ return [
|
||||
'featured_args' => $featured_args,
|
||||
'categories' => $categories,
|
||||
'current_cats' => $current_cats,
|
||||
'topics' => $topics,
|
||||
'current_topics' => $current_topics,
|
||||
'custom_dimensions' => $custom_dimensions,
|
||||
'current_cf' => $current_cf,
|
||||
'current_title' => $current_title,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Reference-theme article parameters sidebar.
|
||||
* Article parameters sidebar.
|
||||
*
|
||||
* @var array $ctx
|
||||
* @package Jio
|
||||
@@ -41,6 +41,16 @@ require_once get_template_directory() . '/templates/parts/submit/term-checks.php
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!empty($settings['allow_topics']) && !empty($ctx['topics'])) : ?>
|
||||
<div class="newpost-topics-drop drop-select dropdown dependency-box">
|
||||
<button type="button" data-toggle-class="open" data-target=".newpost-topics-drop" class="flex ac jsb drop-btn form-control mb6">
|
||||
<span class="title-theme222"><i class="fa fas fa-cube mr6" aria-hidden="true"></i><?php esc_html_e('专题', 'jio'); ?></span><i class="ml6 fa fas fa-angle-right em12"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu fluid"><div class="mini-scrollbar padding-w10 select-drop-box">
|
||||
<?php jio_submit_render_term_checks($ctx['topics'], $ctx['current_topics'], 'topics'); ?>
|
||||
</div></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($settings['custom_filter_s']) && !empty($ctx['custom_dimensions'])) : ?>
|
||||
<?php foreach ($ctx['custom_dimensions'] as $dimension) :
|
||||
|
||||
@@ -13,11 +13,20 @@ defined('ABSPATH') || exit;
|
||||
if (!function_exists('jio_submit_render_term_checks')) :
|
||||
function jio_submit_render_term_checks(array $terms, array $checked, string $name, int $parent = 0, int $depth = 0): void {
|
||||
$children_map = [];
|
||||
$present = [];
|
||||
foreach ($terms as $term) {
|
||||
if ($term instanceof WP_Term) {
|
||||
$present[(int) $term->term_id] = true;
|
||||
}
|
||||
}
|
||||
foreach ($terms as $term) {
|
||||
if (!$term instanceof WP_Term) {
|
||||
continue;
|
||||
}
|
||||
$pid = (int) $term->parent;
|
||||
if ($pid !== 0 && !isset($present[$pid])) {
|
||||
$pid = 0;
|
||||
}
|
||||
if (!isset($children_map[$pid])) {
|
||||
$children_map[$pid] = [];
|
||||
}
|
||||
@@ -38,20 +47,6 @@ if (!function_exists('jio_submit_render_term_checks')) :
|
||||
}
|
||||
};
|
||||
|
||||
// If include list was used without hierarchy, still render flat.
|
||||
if (empty($children_map) && !empty($terms)) {
|
||||
foreach ($terms as $term) {
|
||||
if (!$term instanceof WP_Term) {
|
||||
continue;
|
||||
}
|
||||
$tid = (int) $term->term_id;
|
||||
echo '<div><label class="jio-submit-check">';
|
||||
echo '<input type="checkbox" name="' . esc_attr($name) . '[]" value="' . esc_attr((string) $tid) . '"' . (in_array($tid, $checked, true) ? ' checked' : '') . '>';
|
||||
echo '<span>' . esc_html($term->name) . '</span></label></div>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$render($parent, $depth);
|
||||
}
|
||||
endif;
|
||||
Reference in new issue
Block a user