Featured Pages
Creating Featured Pages for Elgg 1.8 
Open the file
elgg\mod\pages\start.php
Add this code into section Register some actions
elgg_register_action("pages/featured","$action_base/featured.php");
In the folder
elgg\mod\pages\actions\pages\
Create new file
featured.php
With this code
<?php
global $CONFIG;
admin_gatekeeper();
$page_guid = get_input('page_guid');
$action = get_input('action_type');
$page = get_entity($page_guid);
if($page){
if($action == "feature"){
$page->featured_page = "yes";
system_message(elgg_echo('page:featuredon'));
}
if($action == "unfeature"){
$page->featured_page = "no";
system_message(elgg_echo('page:unfeatured'));
}
}
forward(REFERER);
?>
Open the file
elgg\mod\pages\start.php
After this code
if (!elgg_is_admin_logged_in() && elgg_get_logged_in_user_guid() != $entity->getOwnerGuid()) {
foreach ($return as $index => $item) {
if ($item->getName() == 'delete') {
unset($return[$index]);
}
}
}
Add this code
if (elgg_is_admin_logged_in()) {
if ($entity->featured_page == "yes") {
$url = "action/pages/featured?page_guid={$entity->guid}&action_type=unfeature";
$wording = elgg_echo("pages:makeunfeatured");
} else {
$url = "action/pages/featured?page_guid={$entity->guid}&action_type=feature";
$wording = elgg_echo("pages:makefeatured");
}
$options = array(
'name' => 'feature',
'text' => $wording,
'href' => $url,
'priority' => 300,
'is_action' => true
);
$return[] = ElggMenuItem::factory($options);
}
Open the file
elgg\mod\pages\languages\en.php
And add this code
'pages:makefeatured' => "Recommend",
'pages:makeunfeatured' => "UnRecommend",
'page:featuredon' => "This Page was successfully Recommend",
'page:unfeatured' => "This Page was successfully UnRecommend",
'pages:featured' => "Featured Pages",
Adding Featured Pages in Sidebar
Open the file
elgg\mod\pages\pages\pages\world.php
Change this code
$body = elgg_view_layout('content', array(
'filter_context' => 'all',
'content' => $content,
'title' => $title,
'sidebar' => elgg_view('pages/sidebar'),
));
With this
$sidebar = elgg_view('pages/sidebar');
$sidebar .= elgg_view('pages/sidebar/featured');
$body = elgg_view_layout('content', array(
'filter_context' => 'all',
'content' => $content,
'title' => $title,
'sidebar' => $sidebar,
));
In the folder
elgg\mod\pages\views\default\pages\sidebar\
Create new file
featured.php
With this code
<?php
$featured_page = elgg_get_entities_from_metadata(array(
'metadata_name' => 'featured_page',
'metadata_value' => 'yes',
'object' => 'page',
'limit' => 10,
));if ($featured_page) {
elgg_push_context('widgets');
$body = '';
foreach ($featured_page as $page) {
$body .= elgg_view_entity($page, array('full_view' => false));
}
elgg_pop_context();echo elgg_view_module('aside', elgg_echo("pages:featured"), $body);
}




For featured pictures/file what modifications are required?
Create the similar actions in mod/file/start.php and mod/tidypics/start.php.
Then create the file featured.php in mod\file\actions\file\ and mod\tidypics\actions\photos\
Just replace the aboving codes (for Pages) with codes for File and TidyPics (image/album)
Sorry to bother, mate.
Where would the code need to be inserted in start.php for tidypics?
Best Regards
After this code
elgg_register_action("photos/album/set_cover", "$base_dir/album/set_cover.ph
Add this code
elgg_register_action("photos/album/featured","$base_dir/album/featured.php");
And after this code
if ($entity->canEdit()) {
$options = array(
'name' => 'sort',
'text' => elgg_echo('album:sort'),
'href' => "photos/sort/" . $entity->getGUID(),
'priority' => 90,
);
$return[] = ElggMenuItem::factory($options);
}
Add this code
if (elgg_is_admin_logged_in()) {
if ($entity->featured_album == "yes") {
$url = "action/photos/album/featured?album_guid={$entity->guid}&action_type=unfeature";
$wording = elgg_echo("album:makeunfeatured");
} else {
$url = "photos/album/featured?album_guid={$entity->guid}&action_type=feature";
$wording = elgg_echo("album:makefeatured");
}
$options = array(
'name' => 'feature',
'text' => $wording,
'href' => $url,
'priority' => 300,
'is_action' => true
);
$return[] = ElggMenuItem::factory($options);
}
Thank you for taking your time, mate! Great stuff!!!
Uh, and additional question: would it be possible to make a user featured by any chance using the same technique?
You can create ANY featured item: http://elgghacks.com/featured-pages/comment-page-1/#comment-12179
Nice one!