如何在elgg中将小部件内容显示到其他非小部件文件中

时间:2016-10-26 05:40:46

标签: php widget elgg

I want to display widget content into non-widget view file.
    but that procedure i don't know.
    pls. help me, get me some extension or information about that.
    in Elgg.

将从likes_content获取代码插件文件为 elgg.2.2.1 \ mod \ likes_content \ views \ default \ widgets \ likes_con tent \ content.php

将此代码粘贴到

elgg.2.2.1 \ mod \ profile \ views \ default \ profile \ owner_block.php

一些,我做过的改变......现在

                 $widget = $vars['entity'];                            
                 $container = $widget->getContainerEntity();    // problem here                     
                 $options =eligo_get_display_entities_options($widget); // and, problem is here                          
                $options['annotation_names'] = array('likes');

                if (elgg_instanceof($container, 'user') && $widget->my_likes !== 0) {
                  $options['annotation_owner_guids'] = $container->guid;
                }

                if (!elgg_instanceof($container, 'user') && !elgg_instanceof($container, 'group')) {
                  unset($options['container_guids']);
                }


                if ($widget->eligo_sortby == 'mostliked') {
                  $dbprefix = elgg_get_config('dbprefix');
                  $likes_metastring = get_metastring_id('likes');
                  $options['selects'] = array("(SELECT count(distinct l.id) FROM {$dbprefix}annotations l WHERE l.name_id = $likes_metastring AND l.entity_guid = e.guid) AS likes");

                  $options['order_by'] = 'likes ASC';
                  if ($widget->eligo_sortby_dir == 'desc') {
                    $options['order_by'] = 'likes DESC';
                  }
                }

                $content = elgg_list_entities_from_annotations($options);

2 个答案:

答案 0 :(得分:0)

是的,您可以借助功能dynamic_sidebar()(即https://codex.wordpress.org/Function_Reference/dynamic_sidebar

在任意位置显示它
dynamic_sidebar('your-widget-id');

答案 1 :(得分:0)

在Elgg中,每个小部件也是一个视图。所以你可以使用下面的一行

elgg_view('widgets\liked_con‌​tent\content');

但在这种情况下,你应该注意加载你的params权利

另一种方法是以下

echo elgg_view_layout('widgets', array (
'title' => 'Give a title',
'content' => elgg_view ( 'widgets/mycustomwidget/content' ),
'show_add_widgets' => false,
));

" mycustomwidget"是我们想要显示它的小部件的名称。