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
@@ -385,11 +385,6 @@ add_action('pre_get_posts', function ($query) {
|
||||
// 站内搜索:分类/标签名搜索(内容类型始终为 post)
|
||||
if ($query->is_search() && empty($query->get('post_type'))) {
|
||||
$search_type = sanitize_key((string) $query->get('type'));
|
||||
$trem = absint($query->get('trem'));
|
||||
if ($trem > 0) {
|
||||
$query->set('cat', $trem);
|
||||
}
|
||||
|
||||
if (in_array($search_type, ['category', 'tag'], true)) {
|
||||
$taxonomy = $search_type === 'category' ? 'category' : 'post_tag';
|
||||
$term_ids = get_terms([
|
||||
|
||||
@@ -80,6 +80,9 @@ if (!function_exists('jio_header_slide_current_page_type')) {
|
||||
if (is_tag()) {
|
||||
return 'tag';
|
||||
}
|
||||
if (function_exists('is_tax') && is_tax('topics')) {
|
||||
return 'topics';
|
||||
}
|
||||
if (is_singular('post')) {
|
||||
return 'single';
|
||||
}
|
||||
|
||||
@@ -122,7 +122,9 @@ if (!function_exists('jio_homepage_get_tab_panes_html')) {
|
||||
|
||||
$html = '';
|
||||
foreach ($tab_configs as $index => $tab_cfg) {
|
||||
$config = jio_archive_get_render_config(['context' => 'category', 'term_id' => (int) $tab_cfg['term_id']]);
|
||||
$term = $tab_cfg['term'] ?? null;
|
||||
$context = $term instanceof WP_Term && $term->taxonomy === 'topics' ? 'topics' : 'category';
|
||||
$config = jio_archive_get_render_config(['context' => $context, 'term_id' => (int) $tab_cfg['term_id']]);
|
||||
$is_card = ($config['mode'] ?? 'list') === 'card';
|
||||
$placeholder = jio_render_placeholder($is_card ? 'card' : 'list', $is_card ? (wp_is_mobile() ? 4 : 12) : (wp_is_mobile() ? 4 : 6));
|
||||
$html .= '<div class="ajaxpager tab-pane fade" id="index-tab-' . (int) $index . '">';
|
||||
|
||||
@@ -21,8 +21,10 @@ if (!function_exists('jio_archive_render_term_header')) :
|
||||
}
|
||||
$term = get_queried_object();
|
||||
$is_tag = $term instanceof WP_Term && $term->taxonomy === 'post_tag';
|
||||
$is_topic = $term instanceof WP_Term && $term->taxonomy === 'topics';
|
||||
$paged = max(1, (int) get_query_var('paged', 1));
|
||||
$title = '<i class="fa fas ' . ($is_tag ? 'fa-tags' : 'fa-folder-open') . ' em12 mr10 ml6" aria-hidden="true"></i>' . esc_html((string) $args['title']);
|
||||
$icon = $is_topic ? 'fa-cube' : ($is_tag ? 'fa-tags' : 'fa-folder-open');
|
||||
$title = '<i class="fa fas ' . $icon . ' em12 mr10 ml6" aria-hidden="true"></i>' . esc_html((string) $args['title']);
|
||||
global $wp_query;
|
||||
if (!empty($args['post_count']) && $paged === 1) {
|
||||
$count = $wp_query instanceof WP_Query ? (int) $wp_query->found_posts : 0;
|
||||
@@ -34,7 +36,7 @@ if (!function_exists('jio_archive_render_term_header')) :
|
||||
$edit_url = !$is_tag && current_user_can('edit_term', (int) $term->term_id)
|
||||
? get_edit_term_link((int) $term->term_id, $term->taxonomy)
|
||||
: false;
|
||||
$edit_label = __('编辑此分类', 'jio');
|
||||
$edit_label = $is_topic ? __('编辑此专题', 'jio') : ($is_tag ? __('编辑此标签', 'jio') : __('编辑此分类', 'jio'));
|
||||
$edit_button = $edit_url
|
||||
? '<a class="admin-edit" href="' . esc_url($edit_url) . '" title="' . esc_attr($edit_label) . '"><i class="fa fas fa-edit" aria-hidden="true"></i><span class="screen-reader-text">' . esc_html($edit_label) . '</span></a>'
|
||||
: '';
|
||||
@@ -111,15 +113,15 @@ endif;
|
||||
|
||||
if (!function_exists('jio_archive_build_term_filter_group')) :
|
||||
/**
|
||||
* Build one ordered category/tag filter group from the page-display fieldset.
|
||||
* Build one ordered term filter group from the page-display fieldset.
|
||||
*
|
||||
* @param string $taxonomy category|post_tag.
|
||||
* @param string $taxonomy category|post_tag|topics.
|
||||
* @param array<string,mixed> $option lists/dropdown/dropdown_lists fieldset.
|
||||
* @param string $label Visible group label.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
function jio_archive_build_term_filter_group(string $taxonomy, array $option, string $label): array {
|
||||
if (!in_array($taxonomy, ['category', 'post_tag'], true)) {
|
||||
if (!in_array($taxonomy, ['category', 'post_tag', 'topics'], true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -169,7 +171,8 @@ if (!function_exists('jio_archive_build_term_filter_group')) :
|
||||
}
|
||||
}
|
||||
if ($child_ids) {
|
||||
$child_group = jio_archive_build_term_filter_group($taxonomy, ['lists' => array_unique($child_ids)], $taxonomy === 'category' ? __('子分类', 'jio') : __('子标签', 'jio'));
|
||||
$child_label = $taxonomy === 'topics' ? __('子专题', 'jio') : ($taxonomy === 'category' ? __('子分类', 'jio') : __('子标签', 'jio'));
|
||||
$child_group = jio_archive_build_term_filter_group($taxonomy, ['lists' => array_unique($child_ids)], $child_label);
|
||||
if ($child_group) {
|
||||
$group['children'][] = $child_group;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ if (!function_exists('jio_resolve_post_list_render_config')) :
|
||||
$context = 'category';
|
||||
} elseif (is_tag()) {
|
||||
$context = 'tag';
|
||||
} elseif (function_exists('is_tax') && is_tax('topics')) {
|
||||
$context = 'topics';
|
||||
} elseif (is_author()) {
|
||||
$context = 'author';
|
||||
} elseif (is_search()) {
|
||||
@@ -55,6 +57,7 @@ if (!function_exists('jio_resolve_post_list_render_config')) :
|
||||
'is_home' => $context === 'home',
|
||||
'is_category' => $context === 'category',
|
||||
'is_tag' => $context === 'tag',
|
||||
'is_topics' => $context === 'topics',
|
||||
'is_author' => $context === 'author',
|
||||
'is_search' => $context === 'search',
|
||||
];
|
||||
|
||||
@@ -48,7 +48,7 @@ if (!function_exists('jio_homepage_get_post_types')) {
|
||||
|
||||
if (!function_exists('jio_homepage_get_tab_configs')) {
|
||||
/**
|
||||
* Homepage category tabs with full config.
|
||||
* Homepage term tabs with full config.
|
||||
*
|
||||
* Returns enabled tabs in config order, each with 'term', 'title', 'orderby'.
|
||||
* Preserves every configured row in the saved order.
|
||||
@@ -76,7 +76,7 @@ if (!function_exists('jio_homepage_get_tab_configs')) {
|
||||
if (!$term || is_wp_error($term)) {
|
||||
continue;
|
||||
}
|
||||
if ($term->taxonomy !== 'category' || (int) $term->count === 0) {
|
||||
if (!in_array($term->taxonomy, ['category', 'topics'], true) || (int) $term->count === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ endif;
|
||||
|
||||
if (!function_exists('jio_get_single_article_tags_html')) :
|
||||
/**
|
||||
* Categories → tags.
|
||||
* Categories, topics and tags.
|
||||
*/
|
||||
function jio_get_single_article_tags_html(int $post_id): string {
|
||||
$cats = get_the_category($post_id) ?: [];
|
||||
@@ -230,6 +230,13 @@ if (!function_exists('jio_get_single_article_tags_html')) :
|
||||
'<i class="fa fas fa-folder-open" aria-hidden="true"></i> ',
|
||||
['c-blue', 'c-yellow', 'c-green', 'c-purple', 'c-red']
|
||||
);
|
||||
$topics = get_the_terms($post_id, 'topics');
|
||||
$topic_html = is_array($topics) ? jio_get_colored_term_tags(
|
||||
$topics,
|
||||
'but ml6 radius',
|
||||
'<i class="fa fas fa-cube" aria-hidden="true"></i> ',
|
||||
['c-blue', 'c-yellow', 'c-green', 'c-purple', 'c-red']
|
||||
) : '';
|
||||
|
||||
$tags_html = '';
|
||||
$tags = get_the_tags($post_id) ?: [];
|
||||
@@ -246,7 +253,7 @@ if (!function_exists('jio_get_single_article_tags_html')) :
|
||||
}
|
||||
}
|
||||
|
||||
$top = $cat_html;
|
||||
$top = $cat_html . $topic_html;
|
||||
if ($top === '' && $tags_html === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -40,13 +40,16 @@ endif;
|
||||
|
||||
if (!function_exists('jio_widget_term_cover_url')) :
|
||||
/**
|
||||
* Category cover image URL, resolved through the theme's canonical chain:
|
||||
* Term cover image URL, resolved through the theme's canonical chain:
|
||||
* explicit term cover → latest thumbnailed post inside the term → optional
|
||||
* default placeholder. The reference hides term cards without a real cover
|
||||
* while the aggregation card always falls back to a default image, so the
|
||||
* last step is opt-in via $default_fallback.
|
||||
* default placeholder. The last step is opt-in via $default_fallback.
|
||||
*/
|
||||
function jio_widget_term_cover_url(int $term_id, bool $default_fallback = false): string {
|
||||
function jio_widget_term_cover_url(int $term_id, bool $default_fallback = false, string $taxonomy = 'category'): string {
|
||||
$taxonomy = $taxonomy === 'topics' ? 'topics' : 'category';
|
||||
$cover = class_exists('Jio\\Core\\TermMeta') ? \Jio\Core\TermMeta::get_meta_value($term_id, 'cover_url', '') : '';
|
||||
if (is_string($cover) && $cover !== '') {
|
||||
return esc_url_raw($cover);
|
||||
}
|
||||
$cover_id = (int) get_term_meta($term_id, 'jio_category_cover_id', true);
|
||||
if ($cover_id > 0) {
|
||||
$url = wp_get_attachment_url($cover_id);
|
||||
@@ -54,21 +57,29 @@ if (!function_exists('jio_widget_term_cover_url')) :
|
||||
return (string) $url;
|
||||
}
|
||||
}
|
||||
$posts = get_posts([
|
||||
'category__in' => [$term_id],
|
||||
$term_query = $taxonomy === 'topics'
|
||||
? ['tax_query' => [['taxonomy' => 'topics', 'field' => 'term_id', 'terms' => [$term_id]]]]
|
||||
: ['category__in' => [$term_id]];
|
||||
$posts = get_posts(array_merge($term_query, [
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'publish',
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'meta_query' => [['key' => '_thumbnail_id', 'compare' => 'EXISTS']],
|
||||
'fields' => 'ids',
|
||||
]);
|
||||
]));
|
||||
if (!empty($posts)) {
|
||||
$url = get_the_post_thumbnail_url((int) $posts[0], 'medium_large');
|
||||
if ($url) {
|
||||
return (string) $url;
|
||||
}
|
||||
}
|
||||
if ($default_fallback && $taxonomy === 'topics' && class_exists('Jio\\Settings\\Settings')) {
|
||||
$settings = \Jio\Settings\Settings::get_topics_page_settings();
|
||||
if (!empty($settings['default_cover'])) {
|
||||
return esc_url_raw((string) $settings['default_cover']);
|
||||
}
|
||||
}
|
||||
return $default_fallback ? get_template_directory_uri() . '/assets/img/placeholder.svg' : '';
|
||||
}
|
||||
endif;
|
||||
@@ -190,20 +201,22 @@ endif;
|
||||
|
||||
if (!function_exists('jio_widget_term_aggregation')) :
|
||||
/**
|
||||
* Category aggregation card: cover + description + latest posts list.
|
||||
* Term aggregation card: cover + description + latest posts list.
|
||||
*
|
||||
* @param array<string,mixed> $args {term_id, target_blank, orderby, order, count}.
|
||||
* @param array<string,mixed> $args {term_id, taxonomy, target_blank, orderby, order, count}.
|
||||
*/
|
||||
function jio_widget_term_aggregation(array $args = []): string {
|
||||
$args = wp_parse_args($args, [
|
||||
'term_id' => 0,
|
||||
'taxonomy' => 'category',
|
||||
'target_blank' => false,
|
||||
'orderby' => 'modified',
|
||||
'order' => 'DESC',
|
||||
'count' => 4,
|
||||
]);
|
||||
$term_id = (int) $args['term_id'];
|
||||
$term = $term_id > 0 ? get_term($term_id, 'category') : null;
|
||||
$taxonomy = $args['taxonomy'] === 'topics' ? 'topics' : 'category';
|
||||
$term = $term_id > 0 ? get_term($term_id, $taxonomy) : null;
|
||||
if (!$term instanceof WP_Term || is_wp_error($term)) {
|
||||
return '';
|
||||
}
|
||||
@@ -214,11 +227,11 @@ if (!function_exists('jio_widget_term_aggregation')) :
|
||||
}
|
||||
$href = esc_url((string) $href);
|
||||
|
||||
$img = jio_widget_term_cover_url((int) $term->term_id, true);
|
||||
$img = jio_widget_term_cover_url((int) $term->term_id, true, $taxonomy);
|
||||
$img_html = jio_graphic_card([
|
||||
'class' => '',
|
||||
'img' => $img,
|
||||
'alt' => __('分类', 'jio') . '-' . $term->name,
|
||||
'alt' => ($taxonomy === 'topics' ? __('专题', 'jio') : __('分类', 'jio')) . '-' . $term->name,
|
||||
'link' => ['url' => $href, 'target' => !empty($args['target_blank']) ? '_blank' : ''],
|
||||
'height_scale' => 0,
|
||||
'mask_opacity' => 0,
|
||||
@@ -229,13 +242,16 @@ if (!function_exists('jio_widget_term_aggregation')) :
|
||||
$name = '<a class="em14 key-color text-ellipsis"' . $target . ' href="' . $href . '">' . esc_html($term->name) . '</a>';
|
||||
$description = wp_kses_post((string) $term->description);
|
||||
if ($description === '' && current_user_can('manage_categories')) {
|
||||
$description = esc_html__('请在WordPress后台-文章-文章分类中添加描述!', 'jio')
|
||||
. '<a href="' . esc_url(get_edit_term_link($term_id, 'category')) . '">' . esc_html__('立即编辑', 'jio') . '</a>';
|
||||
$description = $taxonomy === 'topics'
|
||||
? esc_html__('请在WordPress后台-文章-专题中添加描述!', 'jio')
|
||||
: esc_html__('请在WordPress后台-文章-文章分类中添加描述!', 'jio');
|
||||
$description .= '<a href="' . esc_url(get_edit_term_link($term_id, $taxonomy)) . '">' . esc_html__('立即编辑', 'jio') . '</a>';
|
||||
}
|
||||
$description = '<div class="text-ellipsis-2 muted-color">' . $description . '</div>';
|
||||
|
||||
$query_args = [
|
||||
'cat' => (string) $term->term_id,
|
||||
'topics' => $taxonomy === 'topics' ? (string) $term->term_id : '',
|
||||
'cat' => $taxonomy === 'category' ? (string) $term->term_id : '',
|
||||
'orderby' => (string) $args['orderby'],
|
||||
'order' => strtoupper((string) $args['order']) === 'ASC' ? 'ASC' : 'DESC',
|
||||
'count' => max(1, (int) $args['count']),
|
||||
|
||||
@@ -23,6 +23,7 @@ if (!function_exists('jio_renderer_defaults')) {
|
||||
'is_home' => is_home() || is_front_page(),
|
||||
'is_author' => is_author(),
|
||||
'is_tag' => is_tag(),
|
||||
'is_topics' => function_exists('is_tax') && is_tax('topics'),
|
||||
'highlight_query' => '',
|
||||
'wrapper_class' => '',
|
||||
'skip_wrapper' => false,
|
||||
@@ -56,6 +57,7 @@ if (!function_exists('jio_renderer_config')) {
|
||||
}
|
||||
if (!$is_forced && !$is_card) {
|
||||
$is_card = (!empty($args['is_tag']) && !empty($list['list_card_tag']))
|
||||
|| (!empty($args['is_topics']) && !empty($list['list_card_topics']))
|
||||
|| (!empty($args['is_home']) && !empty($list['list_card_home']))
|
||||
|| (!empty($args['is_author']) && !empty($list['list_card_author']));
|
||||
}
|
||||
@@ -83,7 +85,7 @@ if (!function_exists('jio_renderer_config')) {
|
||||
$args['show_time'] = !empty($list['post_list_time']);
|
||||
$args['time_source'] = (string) ($list['post_time_source'] ?? 'modified');
|
||||
$args['list_orderby'] = (string) ($list['list_orderby'] ?? 'modified');
|
||||
$args['badge_types'] = (array) ($list['list_badge_show'] ?? ['pay', 'cat', 'tag']);
|
||||
$args['badge_types'] = (array) ($list['list_badge_show'] ?? ['pay', 'topics', 'cat', 'tag']);
|
||||
$args['mult_thumb_cat'] = (array) ($list['mult_thumb_cat'] ?? []);
|
||||
$args['thumb'] = $thumb;
|
||||
$args['allow_conditional_layout'] = jio_is_show_sidebar() || wp_is_mobile();
|
||||
|
||||
@@ -17,6 +17,8 @@ if (!function_exists('jio_renderer_collect_post_data')) {
|
||||
|
||||
$images = jio_renderer_resolve_images($post_id, $cfg);
|
||||
$categories = get_the_category($post_id) ?: [];
|
||||
$topics = get_the_terms($post_id, 'topics');
|
||||
$topics = is_array($topics) ? $topics : [];
|
||||
$tags = get_the_tags($post_id) ?: [];
|
||||
$content_images = (array) $images['gallery'];
|
||||
$gallery = array_slice($content_images, 0, 4);
|
||||
@@ -84,6 +86,7 @@ if (!function_exists('jio_renderer_collect_post_data')) {
|
||||
'is_mult_thumb' => $is_mult_thumb,
|
||||
'is_no_thumb' => $is_no_thumb,
|
||||
'categories' => $categories,
|
||||
'topics' => $topics,
|
||||
'tags' => $tags,
|
||||
'author_id' => $author_id,
|
||||
'author_name' => $author instanceof WP_User ? $author->display_name : '',
|
||||
@@ -261,6 +264,15 @@ if (!function_exists('jio_renderer_badges')) {
|
||||
$items[] = '<a class="but ' . esc_attr($colors[$index % count($colors)]) . '" title="' . esc_attr__('查看更多分类文章', 'jio') . '" href="' . esc_url(get_category_link($category->term_id)) . '"><i class="fa fas fa-folder-open" aria-hidden="true"></i>' . esc_html($category->name) . '</a>';
|
||||
}
|
||||
}
|
||||
if (empty($cfg['is_topics']) && in_array('topics', $types, true)) {
|
||||
foreach (array_slice((array) ($data['topics'] ?? []), 0, 3) as $topic) {
|
||||
$link = get_term_link($topic);
|
||||
if (is_wp_error($link)) {
|
||||
continue;
|
||||
}
|
||||
$items[] = '<a class="but" title="' . esc_attr__('查看此专题更多文章', 'jio') . '" href="' . esc_url($link) . '"><i class="fa fas fa-cube" aria-hidden="true"></i>' . esc_html($topic->name) . '</a>';
|
||||
}
|
||||
}
|
||||
if (empty($cfg['is_tag']) && in_array('tag', $types, true)) {
|
||||
$tags = (array) $data['tags'];
|
||||
usort($tags, static fn($left, $right): int => (int) $right->count <=> (int) $left->count);
|
||||
|
||||
@@ -298,7 +298,7 @@ function jio_get_search_facets_data(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
$allowed = ['category', 'post_tag'];
|
||||
$allowed = ['category', 'post_tag', 'topics'];
|
||||
$data = [];
|
||||
foreach ($raw as $taxonomy => $ids) {
|
||||
$taxonomy = sanitize_key((string) $taxonomy);
|
||||
@@ -400,6 +400,7 @@ function jio_get_search_tab_nav_filter(string $type): string {
|
||||
$labels = [
|
||||
'category' => __('分类', 'jio'),
|
||||
'post_tag' => __('标签', 'jio'),
|
||||
'topics' => __('专题', 'jio'),
|
||||
];
|
||||
$current = isset($_REQUEST['trem']) ? absint(wp_unslash($_REQUEST['trem'])) : 0;
|
||||
foreach (jio_get_search_facets_data() as $taxonomy => $terms) {
|
||||
|
||||
@@ -28,6 +28,9 @@ function jio_resolve_sidebar_id(): string {
|
||||
if (is_category()) {
|
||||
return 'cat_sidebar';
|
||||
}
|
||||
if (function_exists('is_tax') && is_tax('topics')) {
|
||||
return 'cat_sidebar';
|
||||
}
|
||||
|
||||
if (is_tag()) {
|
||||
return 'tag_sidebar';
|
||||
@@ -183,7 +186,7 @@ function jio_is_show_sidebar_filter(): bool {
|
||||
if (is_page() && empty($cfg['page'])) {
|
||||
return false;
|
||||
}
|
||||
if (is_category() && empty($cfg['category'])) {
|
||||
if ((is_category() || (function_exists('is_tax') && is_tax('topics'))) && empty($cfg['category'])) {
|
||||
return false;
|
||||
}
|
||||
if (is_tag() && empty($cfg['tag'])) {
|
||||
@@ -194,7 +197,7 @@ function jio_is_show_sidebar_filter(): bool {
|
||||
}
|
||||
|
||||
// Category/tag term meta can still force off (existing Jio contract).
|
||||
if ((is_category() || is_tag()) && class_exists('\Jio\Core\TermMeta') && method_exists('\Jio\Core\TermMeta', 'resolve_archive_settings')) {
|
||||
if ((is_category() || is_tag() || (function_exists('is_tax') && is_tax('topics'))) && class_exists('\Jio\Core\TermMeta') && method_exists('\Jio\Core\TermMeta', 'resolve_archive_settings')) {
|
||||
$term = get_queried_object();
|
||||
if ($term instanceof \WP_Term) {
|
||||
$resolved = \Jio\Core\TermMeta::resolve_archive_settings($term);
|
||||
@@ -214,7 +217,7 @@ function jio_is_show_sidebar_filter(): bool {
|
||||
if (is_page()) {
|
||||
return !empty($cfg['page']);
|
||||
}
|
||||
if (is_category()) {
|
||||
if (is_category() || (function_exists('is_tax') && is_tax('topics'))) {
|
||||
return !empty($cfg['category']);
|
||||
}
|
||||
if (is_tag()) {
|
||||
|
||||
Reference in new issue
Block a user