Different layout for startpage

Skinning and designing Serendipity (CSS, HTML, Smarty)
User avatar
Hannes
Regular
Posts: 26
Joined: Fri Apr 22, 2005 12:46 pm
Location: Vienna
Contact:

Different layout for startpage

Post by Hannes » Wed Sep 07, 2005 8:21 pm

Hi,

for some time I'm looking for a way to give the start page of the blog a unique style. It should only include the posts and one plug-in. The reason is that I want to include a bigger picture on the start page.

Is this possible??? Can only the start page be embedded?

Hope you guys can help me out!!!

Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Different layout for startpage

Post by garvinhicking » Wed Sep 07, 2005 8:54 pm

Yes, you can do that with little Smarty templating and some CSS magic.

Look at http://www.s9y.org/forums/viewtopic.php ... p+category or http://www.s9y.org/forums/viewtopic.php ... p+category

You can easily make very different if-structures once you have the "categoryid" variable in your template.

For serendipity 0.9 there's a "categorytemplates" plugin that allows you to have different template for each category, this may also be a solution for you.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Hannes
Regular
Posts: 26
Joined: Fri Apr 22, 2005 12:46 pm
Location: Vienna
Contact:

Post by Hannes » Wed Sep 07, 2005 10:12 pm

Thank you for your answer. BUT (this might not be my day)

I don't want the template to be linked with a special category. As I am using no categories (up to now) I don't see this as useful. Only the start page should have a special template. Is it possible to link a plugin with a template? That would make more sense to me (but this must mean nothing :D ).

Maybe you could bring me on the right way.

Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Sep 08, 2005 12:43 pm

The current staticpage plugin is able to define a staticpage as "startpage". You can use that plugin's logic to built your own plugin that switches the template for the startpage only.

This is an example; search for "hanno" to see where you need to customize.

Code: Select all

<?php
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
    include $probelang;
}

class serendipity_event_hanno extends serendipity_event {
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name', 'Hanno');
        $propbag->add('description', '');
        $propbag->add('event_hooks',  array(
            'frontend_generate_plugins'                          => true,
            'genpage'                                            => true));

        $propbag->add('author', 'Garvin Hicking');
        $propbag->add('version', '0.1');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('stackable', false);
        $propbag->add('groups', array('BACKEND_FEATURES'));
    }

    function generate_content(&$title) {
        $title = 'Hanno';
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch ($event) {
                case 'genpage':
                    $args = implode('/', serendipity_getUriArguments($eventData, true));

                    if ((empty($args) || trim($args) == $serendipity['indexFile']) && empty($serendipity['GET']['subpage'])) {
                        $serendipity['GET']['subpage'] = 'customstart';
                        $serendipity['template']       = 'blue'; // HANNO: Insert your template name for the startpage here.
                    }

                    break;

                case 'frontend_generate_plugins':
                    $plugins =& $eventData;
                    if ($serendipity['GET']['subpage'] != 'customstart') {
                        return false;
                    }

                    foreach ($plugins as $idx => $plugin_data) {
                        // HANNO: Insert the name of the single plugin you want to keep here.
                        if ($plugin_data['name'] != 'serendipity_calendar_plugin') {
                            unset($plugins[$idx]);
                        }
                    }
                   
                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}
/* vim: set sts=4 ts=4 expandtab : */


Regards,
Garvin
Last edited by garvinhicking on Thu Sep 08, 2005 3:23 pm, edited 2 times in total.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Hannes
Regular
Posts: 26
Joined: Fri Apr 22, 2005 12:46 pm
Location: Vienna
Contact:

Post by Hannes » Thu Sep 08, 2005 2:13 pm

Thank you very much Garvin. I appreciate your efforts. As I'm (by far) no expert in php and smarty and s9y I would like to ask you some additional questions:

I have copied the code into a new file and called it "serendipity_event_hanno". I created an directory in plugins and copied the file there.
(In line 16 of your code I think there should be a semicolon after true. )

After that I made a new static page called customstart. When I called the site in the browser, the site was displayed with all posts and no sidebar plug-ins, as I have added no plug-in names to the file. The site was displayed with the regular theme. Then I wanted to change the theme for this static site and change line 46 in

Code: Select all

$serendipity['template']       = 'simple';
as I have a simple template. NO changes.

To my surprise the sidebar plug-ins were hidden on all sites not only on this specific static site. After deleting the plug-in the normal layout was displayed of course.

Another questions concerns the "name of the plug-in"? Do you mean the name like saved in the database. Could you give me an example?

Regards,

Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Sep 08, 2005 3:22 pm

Hi Hannes!

I have copied the code into a new file and called it "serendipity_event_hanno". I created an directory in plugins and copied the file there.
(In line 16 of your code I think there should be a semicolon after true. )


That's good so far, and sorry for the typo in line 16. :)

After that I made a new static page called customstart.


MEEEP! That's an error. Static pages are not involved in the plugin at all.

When I called the site in the browser, the site was displayed with all posts and no sidebar plug-ins, as I have added no plug-in names to the file. The site was displayed with the regular theme. Then I wanted to change the theme for this static site and change line 46 in

Code: Select all

$serendipity['template']       = 'simple';
as I have a simple template. NO changes.


You should just call your blog with http://blog/index.php - not the staticpage. Then that template should be shown.

To my surprise the sidebar plug-ins were hidden on all sites not only on this specific static site. After deleting the plug-in the normal layout was displayed of course.


I'm sorry, there was yet another bug in my post because the plugins were always removed, no matter if it were the startpage or not. I've corrected the error in the code above.

Another questions concerns the "name of the plug-in"? Do you mean the name like saved in the database. Could you give me an example?


You need to use the "classname" of the plugin, so yes, the name that is stored in the serendipity_plugins table. Usually the filename without ".php".

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Guest

Post by Guest » Thu Sep 08, 2005 4:59 pm

Thank you for your reply. I have updated the code and followed the instructions.

The template of the startpage does not change :( .
It's still not possible to add one or two specific plugins to the startpage :( . Added the plugin-name like

Code: Select all

'serendipity_plugin_xxx';
.

Is there some other pre-work to do?

Regards,

Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Sep 08, 2005 5:11 pm

What does your plugin file now look like? What is the URL to your blog you use to see if the template gets applied?

You can try to change this part of the plugin:

Code: Select all

                    if ((empty($args) || trim($args) == $serendipity['indexFile']) && empty($serendipity['GET']['subpage'])) {
                        $serendipity['GET']['subpage'] = 'customstart';
                        $serendipity['template']       = 'blue'; // HANNO: Insert your template name for the startpage here.
                        die('TEMPLATE: ' . $serendipity['template']);
                    }  else {
                        die('You did not simply call the startpage, but supplied GET parameters to the page. Serendipity does not recognize this as your startpage.');
                    }


Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Hannes
Regular
Posts: 26
Joined: Fri Apr 22, 2005 12:46 pm
Location: Vienna
Contact:

Post by Hannes » Thu Sep 08, 2005 6:09 pm

Well, after changing this part of the code it shows the text in the else part. You can check it http://www.hannesreiff.com/new/index.php

The new directory is my serendipity dir.

Regards,

Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Sep 08, 2005 7:19 pm

Okay, that brings us a lot closer to the problem.

could you please use this code:

Code: Select all

                  if ((empty($args) || trim($args) == $serendipity['indexFile']) && empty($serendipity['GET']['subpage'])) {
                        $serendipity['GET']['subpage'] = 'customstart';
                        $serendipity['template']       = 'blue'; // HANNO: Insert your template name for the startpage here.
                        die('TEMPLATE: ' . $serendipity['template']);
                    }  else {
                        print_r($args);
                        print_r($serendipity['indexFile']);
                        print_r($serendipity['GET']);
                        die('You did not simply call the startpage, but supplied GET parameters to the page. Serendipity does not recognize this as your startpage.');
                    }


This should show us what parameters are forcing the page not to be recognized as startpage...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Sep 08, 2005 7:22 pm

A second idea is this code:

Code: Select all

                    if ($serendipity['rewrite'] != 'none') {
                        $nice_url = $serendipity['serendipityHTTPPath'] . $args;
                    } else {
                        $nice_url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/' . $args;
                    }

                  if ((empty($args) || trim($args) == $serendipity['indexFile']) && (empty($serendipity['GET']['subpage']) || $serendipity['GET']['subpage'] == $nice_url)) {
                        $serendipity['GET']['subpage'] = 'customstart';
                        $serendipity['template']       = 'blue'; // HANNO: Insert your template name for the startpage here.
                    }  else {
                        print_r($nice_url);
                        print_r($args);
                        print_r($serendipity['indexFile']);
                        print_r($serendipity['GET']);
                        die('You did not simply call the startpage, but supplied GET parameters to the page. Serendipity does not recognize this as your startpage.');
                    }


Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Hannes
Regular
Posts: 26
Joined: Fri Apr 22, 2005 12:46 pm
Location: Vienna
Contact:

Post by Hannes » Thu Sep 08, 2005 7:31 pm

Thank you so much for your efforts!!!

I changed the code with the last improvement. The template is now changing to the one given in the code. It's now the default one.

Links to other subpages or static pages are not working (but I could imagine you know that). Remains the thing with the plugins.

Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Thu Sep 08, 2005 11:53 pm

Try to replace the "subpage" with "custompage" in those occurences:

Code: Select all

$serendipity['GET']['subpage'] = 'customstart';
...
if ($serendipity['GET']['subpage'] != 'customstart') {


Then you should be able to use it without influencing the staticpages.

About the plugins: How does your actual code look like now? Maybe your if-structure is just wrong...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Hannes
Regular
Posts: 26
Joined: Fri Apr 22, 2005 12:46 pm
Location: Vienna
Contact:

Post by Hannes » Fri Sep 09, 2005 1:28 am

Hmm, changed the two lines again - with no visible improvement. It still shows all plugins. the links to the static pages and other subpages don't work.

Here is the plugin if-structure

Code: Select all

case 'frontend_generate_plugins':
                    $plugins = $eventData;
                    if ($serendipity['GET']['custompage'] != 'customstart') {
                        return false;
                    }

                    foreach ($plugins as $idx => $plugin_data) {
                       // HANNO: Insert the name of the single plugin you want to keep here.
                        if ($plugin_data['name'] != 'serendipity_plugin_comments') {
                            unset($plugins[$idx]);
                        }
                    }

Are there some mistakes in this structure? Is this correct when I want the comments-plugin to be visible?

Regards,
Hannes

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Fri Sep 09, 2005 3:31 pm

The plugin-unsetting is only available in serendipity 0.9, I forgot to mention. You are using that, right?

Can you post me your complete plugin code again, please?

I'm away for the weekend, will reply later.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Post Reply