Plugin Directory

Changeset 3458821


Ignore:
Timestamp:
02/11/2026 09:32:12 AM (7 weeks ago)
Author:
infility
Message:

v2.14.53 (20260211) Ben: 新增elepost列表组件的当前分类post功能。

Location:
infility-global/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • infility-global/trunk/infility_global.php

    r3452498 r3458821  
    44Plugin URI: https://www.infility.cn/
    55Description: Infility公共插件
    6 Version: 2.14.52
     6Version: 2.14.53
    77Author: Infility
    88Author URI: https://www.infility.cn/
     
    140140v2.14.43 (20251217) Ben: 修复导入文件漏洞添加nonce
    141141v2.14.52 (20260203) Step: 修复 infility_get_data 接口的安全问题。
     142v2.14.53 (20260211) Ben: 新增elepost列表组件的当前分类post功能。
    142143*/
    143144
     
    145146    function __construct()
    146147    {
    147         define( 'INFILITY_GLOBAL_VERSION', '2.14.51' );
     148        define( 'INFILITY_GLOBAL_VERSION', '2.14.53' );
    148149        define( 'INFILITY_GLOBAL_PATH', plugin_dir_path( __FILE__ ) ); // fullpath/wp-content/plugins/infility-global/ // 有斜杠
    149150        define( 'INFILITY_GLOBAL_URL', plugins_url( '/', __FILE__ ) ); // https://the_domain/wp-content/plugins/infility-global/ // 斜杠是自己加的
  • infility-global/trunk/widgets/elementor-tab/elementor-tab.php

    r3429478 r3458821  
    105105        $show_hierarchical = sanitize_text_field($_POST['show_hierarchical']);
    106106        $post_type = isset($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : 'post';
     107       
     108        $is_curr_post = isset($_POST['is_curr_post']) ? sanitize_text_field($_POST['is_curr_post']) : 'no';
     109        $current_post_id = isset($_POST['current_post_id']) ? intval($_POST['current_post_id']) : 0;
     110        $current_term_id = isset($_POST['current_term_id']) ? intval($_POST['current_term_id']) : 0;
    107111
    108112        // 确定要使用的分类法
     
    135139        }
    136140
    137         $categories = get_terms($taxonomy_args);
     141        if ($is_curr_post === 'yes') {
     142            $current_category_id = 0;
     143            if ($current_term_id) {
     144                $term = get_term($current_term_id, $taxonomy_name);
     145                if ($term && !is_wp_error($term)) {
     146                     $current_category_id = $current_term_id;
     147                }
     148            } elseif ($current_post_id) {
     149                $terms = wp_get_post_terms($current_post_id, $taxonomy_name);
     150                if (!empty($terms) && !is_wp_error($terms)) {
     151                    $current_category_id = $terms[0]->term_id;
     152                }
     153            }
     154
     155            if ($current_category_id) {
     156                // Get children
     157                $taxonomy_args['child_of'] = $current_category_id;
     158                $children = get_terms($taxonomy_args);
     159               
     160                // Get parent (current category)
     161                $parent = get_term($current_category_id, $taxonomy_name);
     162               
     163                if (!is_wp_error($children) && !is_wp_error($parent)) {
     164                    $categories = array_merge([$parent], $children);
     165                } else {
     166                     $categories = get_terms($taxonomy_args);
     167                }
     168            } else {
     169                 $categories = get_terms($taxonomy_args);
     170            }
     171        } else {
     172            $categories = get_terms($taxonomy_args);
     173        }
    138174
    139175        if (is_wp_error($categories)) {
     
    275311        $pagination_type = sanitize_text_field($_POST['pagination_type']);
    276312        $paged = isset($_POST['paged']) ? intval($_POST['paged']) : 1;
     313       
     314        $is_curr_post = isset($_POST['is_curr_post']) ? sanitize_text_field($_POST['is_curr_post']) : 'no';
     315        $current_post_id = isset($_POST['current_post_id']) ? intval($_POST['current_post_id']) : 0;
     316        $current_term_id = isset($_POST['current_term_id']) ? intval($_POST['current_term_id']) : 0;
     317        $taxonomy_type = isset($_POST['taxonomy_type']) ? sanitize_text_field($_POST['taxonomy_type']) : '';
     318        $custom_taxonomy = isset($_POST['custom_taxonomy']) ? sanitize_text_field($_POST['custom_taxonomy']) : '';
    277319
    278320        // 验证文章类型是否存在
     
    291333        ];
    292334
     335        // Determine taxonomy
     336        $taxonomy = '';
     337        if ($taxonomy_type === 'custom_taxonomy' && !empty($custom_taxonomy)) {
     338            $taxonomy = $custom_taxonomy;
     339        } elseif (!empty($taxonomy_type)) {
     340            $taxonomy = $taxonomy_type;
     341        } else {
     342            $taxonomies = get_object_taxonomies($post_type);
     343            if (!empty($taxonomies)) {
     344                $taxonomy = $taxonomies[0];
     345            }
     346        }
     347
    293348        // 如果分类不是"all",添加分类过滤
    294349        if ($category !== 'all') {
    295             // 获取文章类型的默认分类法
    296             $taxonomies = get_object_taxonomies($post_type);
    297             if (!empty($taxonomies)) {
    298                 $taxonomy = $taxonomies[0]; // 使用第一个分类法
    299 
     350             if ($taxonomy) {
    300351                // 检查是否是一级分类,如果是则包含其子分类
    301352                $term = get_term($category, $taxonomy);
     
    323374                }
    324375            }
     376        } elseif ($is_curr_post === 'yes') {
     377             // Category is 'all', but we want to filter by current context
     378             $current_category_id = 0;
     379             if ($current_term_id) {
     380                 // Verify term belongs to taxonomy
     381                 $term = get_term($current_term_id, $taxonomy);
     382                 if ($term && !is_wp_error($term)) {
     383                     $current_category_id = $current_term_id;
     384                 }
     385             } elseif ($current_post_id) {
     386                 $terms = wp_get_post_terms($current_post_id, $taxonomy);
     387                 if (!empty($terms) && !is_wp_error($terms)) {
     388                     $current_category_id = $terms[0]->term_id;
     389                 }
     390             }
     391             
     392             if ($current_category_id) {
     393                 // Same logic as selected category: include children
     394                $child_terms = get_terms([
     395                    'taxonomy' => $taxonomy,
     396                    'parent' => $current_category_id,
     397                    'hide_empty' => false,
     398                ]);
     399
     400                $category_ids = [$current_category_id];
     401                if (!is_wp_error($child_terms)) {
     402                    foreach ($child_terms as $child_term) {
     403                        $category_ids[] = $child_term->term_id;
     404                    }
     405                }
     406
     407                $args['tax_query'] = [
     408                    [
     409                        'taxonomy' => $taxonomy,
     410                        'field' => 'term_id',
     411                        'terms' => $category_ids,
     412                        'operator' => 'IN',
     413                    ]
     414                ];
     415             }
    325416        }
    326417
  • infility-global/trunk/widgets/elementor-tab/includes/widgets/elementor_nav_posts.php

    r3437335 r3458821  
    143143                ],
    144144                'description' => '输入自定义分类法的名称(slug)',
     145            ]
     146        );
     147
     148        $this->add_control(
     149            'is_curr_post',
     150            [
     151                'label' => '是否显示当前分类post',
     152                'type' => \Elementor\Controls_Manager::SWITCHER,
     153                'default' => 'no',
     154                'label_on' => '是',
     155                'label_off' => '否',
     156                'description' => '是否显示分类的层级结构',
    145157            ]
    146158        );
     
    10691081                    show_excerpt: '<?php echo esc_js($settings['show_excerpt']); ?>',
    10701082                    show_date: '<?php echo esc_js($settings['show_date']); ?>',
    1071                     show_category: '<?php echo esc_js($settings['show_category']); ?>'
     1083                    show_category: '<?php echo esc_js($settings['show_category']); ?>',
     1084                    is_curr_post: '<?php echo esc_js($settings['is_curr_post']); ?>',
     1085                    current_post_id: '<?php echo get_the_ID(); ?>',
     1086                    current_term_id: '<?php echo (is_category() || is_tax() || is_tag()) ? get_queried_object_id() : ""; ?>'
    10721087                };
    10731088
  • infility-global/trunk/widgets/elementor-tab/js/elementor_nav_posts.js

    r3351823 r3458821  
    530530                taxonomy_type: settings.taxonomy_type,
    531531                custom_taxonomy: settings.custom_taxonomy,
     532                is_curr_post: settings.is_curr_post,
     533                current_post_id: settings.current_post_id,
     534                current_term_id: settings.current_term_id,
    532535                show_hierarchical: settings.show_hierarchical,
    533536                nonce: window.elementor_nav_posts_nonce || ''
     
    685688                    category: category,
    686689                    post_type: settings.post_type,
     690                    taxonomy_type: settings.taxonomy_type,
     691                    custom_taxonomy: settings.custom_taxonomy,
    687692                    posts_per_page: settings.show_pagination === 'yes' ? settings.posts_per_page_pagination : settings.posts_per_page,
    688693                    orderby: settings.orderby,
     
    691696                    image_resolution: settings.image_resolution,
    692697                    pagination_type: settings.pagination_type,
     698                    is_curr_post: settings.is_curr_post,
     699                    current_post_id: settings.current_post_id,
     700                    current_term_id: settings.current_term_id,
    693701                    paged:page,
    694702                    nonce: window.elementor_nav_posts_nonce || ''
Note: See TracChangeset for help on using the changeset viewer.