在 elgg 中将默认成员选项卡更改为流行
Change default members tab to popular in elgg
我正在 elgg 中编写一个插件,以将成员列表中 elgg members
的默认选项卡更改为流行而不是 newest
。但有一个问题。当我将默认选项卡设置为 popular
然后 newest
选项卡不再工作。
这是我的 start.php
文件:
<?php
elgg_register_event_handler('init', 'system', 'plug_test_init');
function plug_test_init(){
elgg_unregister_page_handler('members');
elgg_register_page_handler('members', 'set_popular_as_default');
}
function set_popular_as_default($page) {
if (empty($page[0])) {
$page[0] = 'popular';
}
if ($page[0] == 'search') {
echo elgg_view_resource('members/search');
} else {
echo elgg_view_resource('members/index', [
'page' => $page[0],
]);
}
return true;
}
感谢iionly in elgg community, in this discussion会员的using hook解决的问题:
<?php
elgg_register_event_handler('init', 'system', 'plug_test_init');
function plug_test_init(){
elgg_unregister_plugin_hook_handler('members:config', 'tabs', "members_nav_newest");
elgg_register_plugin_hook_handler('members:config', 'tabs', "my_members_nav_newest");
elgg_unregister_page_handler('members');
elgg_register_page_handler('members', 'set_popular_as_default');
}
function set_popular_as_default($page) {
if (empty($page[0])) {
$page[0] = 'popular';
}
if ($page[0] == 'search') {
echo elgg_view_resource('members/search');
} else {
echo elgg_view_resource('members/index', [
'page' => $page[0],
]);
}
return true;
}
function my_members_nav_newest($hook, $type, $returnvalue, $params) {
$returnvalue['newest'] = array(
'title' => elgg_echo('sort:newest'),
'url' => "members/newest",
);
return $returnvalue;
}
我正在 elgg 中编写一个插件,以将成员列表中 elgg members
的默认选项卡更改为流行而不是 newest
。但有一个问题。当我将默认选项卡设置为 popular
然后 newest
选项卡不再工作。
这是我的 start.php
文件:
<?php
elgg_register_event_handler('init', 'system', 'plug_test_init');
function plug_test_init(){
elgg_unregister_page_handler('members');
elgg_register_page_handler('members', 'set_popular_as_default');
}
function set_popular_as_default($page) {
if (empty($page[0])) {
$page[0] = 'popular';
}
if ($page[0] == 'search') {
echo elgg_view_resource('members/search');
} else {
echo elgg_view_resource('members/index', [
'page' => $page[0],
]);
}
return true;
}
感谢iionly in elgg community, in this discussion会员的using hook解决的问题:
<?php
elgg_register_event_handler('init', 'system', 'plug_test_init');
function plug_test_init(){
elgg_unregister_plugin_hook_handler('members:config', 'tabs', "members_nav_newest");
elgg_register_plugin_hook_handler('members:config', 'tabs', "my_members_nav_newest");
elgg_unregister_page_handler('members');
elgg_register_page_handler('members', 'set_popular_as_default');
}
function set_popular_as_default($page) {
if (empty($page[0])) {
$page[0] = 'popular';
}
if ($page[0] == 'search') {
echo elgg_view_resource('members/search');
} else {
echo elgg_view_resource('members/index', [
'page' => $page[0],
]);
}
return true;
}
function my_members_nav_newest($hook, $type, $returnvalue, $params) {
$returnvalue['newest'] = array(
'title' => elgg_echo('sort:newest'),
'url' => "members/newest",
);
return $returnvalue;
}