如何延长团队成员的排序顺序

我正在用Elementor使用RT主题的Business Lounge主题。

WordPress版本为最新版本(5.2.1)

在团队页面上(演示:https://businesslounge-demo.rtthemes.com/our-team/), 列出了团队成员的卡片。我想将团队成员的顺序更改为当前无法选择的选项。

团队成员列表使用简码[staff_box]完成

在Elementor编辑模式下, 我看起来像这样:

在此处输入图片说明

编辑:

编辑表单在

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() );

像这样, 在” wp-content / plugins / businesslounge-extensions / inc / editor / staff_box.php”中定义了编辑表单

<?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

), // ...

输出定义在

wp-content / plugins / businesslounge-extensions / inc / shortcodes / staff_box.php

像这样:

<?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);

// ...

我想做什么:在选择框中添加一个选项” post_name”, 以便我可以按不同的字段对团队进行排序。我要添加”帖子名称” =>”帖子名称”,

如何在不更改原始源代码的情况下执行此操作?

我已经激活了business_lounge主题的子主题。

为此是否需要自定义扩展?

#1

你必须修改原始代码。除非作者对返回的值应用了过滤器或使用了操作, 否则你无法覆盖该函数。

正如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类如何影响短路事件的情况下, 我不确定这是否可行, 但是基于rt_staff()方法, 如果你将短代码用作[staff_box orderby =” post_name”], 则可能会得到预期的结果, 而无需必须触摸任何代码。

#2

你应该能够通过”覆盖”此处所述的功能来修改插件, 而不会失去更新功能:

https://stackoverflow.com/a/40856197/3623080

在你的子主题的functions.php中复制该函数, 对其进行自定义和重命名, 并使用它代替原始函数。

希望对你有帮助

以上是 如何延长团队成员的排序顺序 的全部内容, 来源链接: utcz.com/p/200567.html

回到顶部