Group discussion > Overwriting the default index page

Overwriting the default index page

Ben Werdmuller
696 days ago

To add a little API detail to Dave's excellent instruction above:

The main Elgg index runs a plugin hook called 'index''system'. If this returns true, it assumes that another front page has been drawn, and doesn't display the default.

Therefore, you can override it by registering a function to the 'index' 'system' plugin hook, and then having that function terminate by returning true. This means you can write exactly the front page you want, without having to edit core Elgg. (We recommend you develop this way. This community runs on an untouched core Elgg altered through plugins, for example.)

traveljunkie
695 days ago

Nice one, was looking for that. Now what code would you use to display newest and random users? And I couldn't get the latest activity to work on my custom index.php.

Thanks for the great work!

Pavel M
695 days ago

The same question. I created new index page. It seems all working, but how to include Last activity, Last members etc. Also I see here event plugin. Where to download it?

lord55
694 days ago

is it possible,for example, also for latest.php or others files?...or only for index page?

thanks in advance

Pavel M
694 days ago

Need help!

Where to find the script Newest members to include the only icons of latest members to index page? I can't find it.

Pavel M
694 days ago

2Dave. Nice working! Thank you.

traveljunkie
694 days ago

now if i just knew what  the plugin hook for a custom dashboard is?

traveljunkie
693 days ago

Thanks a lot, Dave!

traveljunkie
692 days ago

Hey Dave,

managed to sort everything out, but just noticed a problem. While php code like <pre>echo $vars['url'];</pre> gets recognized on the custom index page, the custom dashboard page doesn't. Tried to include the Elgg engine, but that obviously wasn't the solution. The only difference betwen the two pages is the html layout in the content area, so that puzzles me a bit.

Cheers!

traveljunkie
692 days ago

Actually, it doesn't work neither on the custom index page. The links just turned out to point to the correct location...

zyon
690 days ago

Yes plz. Post a Demo startpage. :)

 

traveljunkie
690 days ago

It's a lot of code, so I uploaded it here: http://travel-junkie.com/index.txt

zyon
690 days ago

Thx :)

 

lord55
690 days ago

hi! a question:

in my new index.php i must write all like (but i have a white page!):

/**
     * Start the Elgg engine
     */
        require_once(dirname(__FILE__) . "/engine/start.php");
       
       
        if (!trigger_plugin_hook('index','system',null,false)) {
   
            /**
              * Check to see if user is logged in, if not display login form
              **/
               
                if (isloggedin()) forward('pg/dashboard');
               
                         
                //Load the front page guess
                global $CONFIG;
                $title = elgg_view_title(elgg_echo('register'));
               
                $content = elgg_view_layout('one_column', elgg_view("account/forms/register"));
                echo page_draw(null, $content);
         
        }



?>

or only what there is after

if (!trigger_plugin_hook('index','system',null,false)) {

so i write only (now i see a correct page):

/**
              * Check to see if user is logged in, if not display login form
              **/
               
                if (isloggedin()) forward('pg/dashboard');
               
                         
                //Load the front page guess
                global $CONFIG;
                $title = elgg_view_title(elgg_echo('register'));
               
                $content = elgg_view_layout('one_column', elgg_view("account/forms/register"));
                echo page_draw(null, $content);

is this last code correct???

thanks

diane007
687 days ago

Hi

I am very new to PHP and am having trouble creating a custom front page as a plugin :(

Although I have managed to change the content of the default index.php by editing and creating new canvas /layout views, I would like to be able to create a custom index.php plugin as described above.

I guess I must be doing something wrong as all I get is a blank page :(

I created a start.php using Daves above example, changing pluginname to the name of my plugin, for example "customindex"

I then create a index.php file, copying and altering the code from the default index.php

I then uploaded my plugin "customindex" to mod and enabled via tools admin

I am then greeted with my blank page...

Can you help?

Thanks, Diane :)

Alex Morse
686 days ago

Thanks for this.  Just redid our front page, with more tweaks to put in later.  This is much nicer for a landing page when someone clicks the header.

Sean Murricane
686 days ago

Hello,

I think I'm being an eedjit here - forgive the n00b question, but I've put the text from the top into a start.php file, and all it's doing it adding it to the top of mypages as plain text... I know i'm missing something simple, but can someone enlighten me?

 

FAMiNE
686 days ago

Sean... hope you put <?php at the start and ?> at the end of the file...

Sean Murricane
686 days ago

I did, just after posting that (facepalm) and it's now showing up blank - so all I have to do now is put up a proper page... sorry, thanks - I'll no doubt be back with more dumb questions soon :)

 

diane007
686 days ago

@dave

thank you for your reply

I managed to get my plugin working last night by removing

require_once(dirname(__FILE__) . "/engine/start.php");

if (!trigger_plugin_hook('index','system',null,false)) {

from my index.php

so my start.php now reads

 function customindex_init() {

// Extend system CSS with our own styles

extend_view('css','customindex/css');

// Replace the default index page

register_plugin_hook('index','system','new_index');

}

function new_index() {
if (!@include_once(dirname(dirname(__FILE__))) . "/customindex/index.php") return false;

return true;
}

// Make sure the plugin has been registered
register_elgg_event_handler('init','system','customindex_init');

and my index.php

{

/**
* Check to see if user is logged in, if not display login form
**/

if (isloggedin()) forward('pg/dashboard');

//Load the front page
global $CONFIG;

$content = elgg_view_layout('customhome', '', $title . $content, elgg_view("account/forms/login"));
echo page_draw(null, $content);

}

I hope this is correct and will be adding more functions over the next few days

ps. Tried to post this message last night but could not access the community, just a blue screen with database error??

Regards

Diane :)

sr123
660 days ago

@Diane, Thanks for the simple example.  I was finally able to get the plugin for a customindex working instead of getting a blank screen....

@Anyone,

Now I have no idea how to include elements that I want on the index page.  Here is my current index page (which is just basically a copy of the elgg 1.1 default index:

                                if (isloggedin()) forward('pg/dashboard');
                       
                //Load the front page
                        global $CONFIG;
                        $title = elgg_view_title(elgg_echo('content:latest'));
                        set_context('search');
                        $content = list_registered_entities(0,10,true,false,array('object','group'));
                        set_context('main');
                        global $autofeed;
                        $autofeed = false;
                        $content = elgg_view_layout('two_column_left_sidebar', '', $title . $content, elgg_view("account/forms/login"));
                        echo page_draw(null, $content);

I would like to display the latest registered users under the login section in the left side bar, and I would like to display the latest forum activity underneath the latest site activity.

I see the code that Dave Tosh listed above:

For newest members: get_entities('user', '', 0, '', 20, 0, false, 0, null);

But I have no idea how to place it under the login section.

Can anyone help me with this?

 

Thanks,

sr123

diane007
658 days ago

@sr123

In views/default/canvas/layouts/two_column_left_sidebar.php

add the following to the <div id="two_column_left_sidebar"> section

 

$users = get_entities('user', '', 0, '', 25, 0, false, 0, null);
if($users){
foreach($users as $user){
echo "" . elgg_view("profile/icon",array('entity' => $user, 'size' => 'small')) . "";
}
}

I am not sure whether this is correct, but it works for me :)

diane007
658 days ago

Trying to extend the view for my custom index with css.php

in my start.php i have

extend_view('css','customindex/css');

and my css file is located at mod/customindex/views/default/customindex/css.php  but this overrides the default css and affects the entire site. Is this supposed to happen or am I missing something?

Can anyone help, thanks :)

 

Kailas
656 days ago

Hi Diane,

Don't modify views/default/canvas/layouts/two_column_left_sidebar.php directly.

Here is a sample code if you want to show new members in the ront page.

http://community.elgg.org/pg/pages/view/3952/

You can put this code in your plugin index.php file or in your plugin view and load it in the index.php.

Hope this helps!

Dahaniel
583 days ago

Can I somehow exclude wire posts from: list_registered_entities(0,10,true,false,array('object','group'));

I use it on a custom dashboard and show wire posts seperately as a shoutbox.

tino
559 days ago

how do I enable and use views/default/canvas/layouts/two_column_right_sidebar.php

if I try, it distorts the layout and positions everything linearly