如何扩展团队成员的排序顺序 [英] How to extend sorting order of Team Members

查看:49
本文介绍了如何扩展团队成员的排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 到返回的值,或使用 action.

正如 gael 在他的回答中指出的那样,您可以通过将原始代码复制到子主题的 functions.php 然后重命名函数来减轻更新丢失更改的打击 - 例如my_rt_staff() 在添加修改之前.

然而,您仍然需要在插件中调用 my_rt_staff() 而不是 rt_stuff 并且每当插件更新时您都必须进行此更改,但是您不会丢失您的代码.

(也许您可以将默认短代码属性中的 "list_orderby" => "date" 更改为 "list_orderby" => "post_name", 作为默认值在您修改后的 my_rt_staff() 方法中,因此它默认按名称而不是日期排序)

但是,这在您的特定情况下没有多大帮助,因为您需要对控件本身进行理想的修改,在 Widget_RT_Staff 中的 _register_controls() 方法上代码>类.您可以通过扩展 Widget_RT_Staff 来覆盖它,但您仍然需要调用您的新类,这会导致您修改插件代码.

在没有看到 Widget_RT_Staff 类如何影响 shortocde 的情况下,我不能确定这会起作用,但是基于 rt_staff() 方法,如果您使用短代码为 [staff_box orderby="post_name"] 您无需触摸任何代码即可获得预期结果.

I'm using Business Lounge theme by RT themes with Elementor.

Wordpress version is current (5.2.1)

On the team page (Demo: https://businesslounge-demo.rtthemes.com/our-team/) there is a list of cards of team members. I want to change the order of the team members to an option that is not currently selectable.

The team member list is done with a shortcode [staff_box]

In Elementor edit mode I looks like this:

Edit:

The edit form is defined in
wp-content/plugins/businesslounge-extensions/inc/elementor-addons/staff.php

<?php
namespace Elementor;
// ...
class Widget_RT_Staff extends Widget_Base {
  // ...
  protected function _register_controls() {
    // ...
    $this->add_control(
      'list_orderby',
        [
          'label'     => esc_html_x( 'List Order By', 'Admin Panel','businesslounge' ),
          'description' => esc_html_x('Sorts the posts by this parameter', 'Admin Panel','businesslounge' ),    
          'type'      =>  Controls_Manager::SELECT,
          'default'    =>  "date",
          "options"    => array(
            'date' => esc_html_x('Date',"Admin Panel","businesslounge"),
            'author' => esc_html_x('Author',"Admin Panel","businesslounge"),
            'title' => esc_html_x('Title',"Admin Panel","businesslounge"),
            'modified' => esc_html_x('Modified',"Admin Panel","businesslounge"),
            'ID' => esc_html_x('ID',"Admin Panel","businesslounge"),
            'rand' => esc_html_x('Randomized',"Admin Panel","businesslounge"),                                  
          )
        ]
      );     
      // ...
  }
  // ...
}

Plugin::instance()->widgets_manager->register_widget_type( new Widget_RT_Staff() );

The edit form is defined in `wp-content/plugins/businesslounge-extensions/inc/editor/staff_box.php` like so

<?php
vc_map(
    array(
        'base'        => 'staff_box',
        'name'        => _x( 'Team', 'Admin Panel','businesslounge' ),
        'icon'        => 'rt_theme rt_team',
        'category'    => array(_x( 'Content', 'Admin Panel','businesslounge' ), _x( 'Theme Addons', 'Admin Panel','businesslounge' )),
        'description' => _x( 'Displays team members', 'Admin Panel','businesslounge' ),
        'params'      => array(
// ...    
          array(
            'param_name'  => 'list_orderby',
            'heading'     => _x( 'List Order By', 'Admin Panel','businesslounge' ),
            "description" => _x("Sorts the posts by this parameter",'Admin Panel','businesslounge'),
            'type'        => 'dropdown',
            "value"       => array(
                                _x('Date','Admin Panel','businesslounge') => 'date',
                                _x('Author','Admin Panel','businesslounge') => 'author',
                                _x('Title','Admin Panel','businesslounge') => 'title',
                                _x('Modified','Admin Panel','businesslounge') => 'modified',
                                _x('ID','Admin Panel','businesslounge') => 'ID',
                                _x('Randomized','Admin Panel','businesslounge') => 'rand',
                            ),
            'save_always' => true
        ),
// ...

The output is defined in
wp-content/plugins/businesslounge-extensions/inc/shortcodes/staff_box.php

like so:

<?php
function rt_staff( $atts, $content = null ) { 
// ...

    //defaults
    extract(shortcode_atts(array(  
        "id"           => 'staff-'.rand(100000, 1000000), 
        "class"        => "", 
        "list_layout"  => "1/1", 
        "list_orderby" => "date",
        "list_order"   => "DESC",
        "ids"          => array(),
        "box_style"    => ""        
    ), $atts));

// ...

    //general query
    $args=array( 
        'post_status'    => 'publish',
        'post_type'      => 'staff',
        'orderby'        => $list_orderby,
        'order'          => $list_order,
        'showposts'      => 1000                                                            
    );
// ...
    $theQuery = query_posts($args);
// ...

What I want to do: Add an option 'post_name' to the select box so that I can sort the team by a different field. I want to add 'Post name' => 'post_name',

How can I do this without changing the original source code?
I already have the child theme of business_lounge theme activated.
Do I need a custom extension for this?

解决方案

You'd have to modify the original code. You can't override the function unless the author applied a filter to the value returned, or used an action.

As gael notes in his answer, you can soften the blow of losing changes on updates by copying the original code into your child theme's functions.php then renaming the function - for e.g. to my_rt_staff() before adding in your modifications.

You would however still need to call the my_rt_staff() in the plugin instead of rt_stuff and you would have to make this change whenever the plugin was updated, but you wouldn't lose your code.

(Perhaps you could change the "list_orderby" => "date" in the default shortcode attributes to "list_orderby" => "post_name", as default in your modified my_rt_staff() method so it orders by name as default instead of date)

However, this does not help much in your specific circumstance, as the ideal modification you need to make is to the control itself, on the _register_controls() method in the Widget_RT_Staff class. You can override this by extending Widget_RT_Staff but you would still need to call your new class which results in you modifying the plugin code.

Without seeing how the Widget_RT_Staff class affects the shortocde, I can't be certain this would work, but based on the rt_staff() method, if you use the shortcode as [staff_box orderby="post_name"] you may get your intended result without having to touch any code.

这篇关于如何扩展团队成员的排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆