Page 1 of 1

Show last 5 entries on site index page

Posted: Mon Jul 10, 2006 9:39 pm
by Johan
I would like to show the last 5 reports on my index page.
This could look simulair like the little box on the right top of each entry.
It should indicate the topic, author, date and link to the actual entry. The link should point to a blanc new page otherwise it will appear in the small iFrame.

I think the easiest would be to make a simple new page called index2.php in the blog directory and use that in an Iframe on the site index page.

My question is how can I do this? What should this index2.php look like?


Thanks,

Hanno

Posted: Mon Jul 10, 2006 10:36 pm
by judebert
If you want to include entries in a static page, Garvin covered something like this here: http://www.s9y.org/forums/viewtopic.php ... &highlight

Of course, instead of using the serendipity_getTemplateFile() call, you'd want to print your entries directly from the PHP associative array.

Since you want these entries to look different from the standard Serendipity blog entries, I'd create a new template -- say, "embedded" or something -- and copy the entries.tpl from templates/default into templates/embedded. Then I'd remove all the bits that display the entry body, extended body, and whatever else you don't want.

Finally, I'd make an index2.php exactly like Garvin's above, but sets Serendipity to use the embedded template:

Code: Select all

<?php
chdir('serendipity'); // Or change this to the name of the directory where you installed s9y in!

# Include the s9y framework
include 'serendipity_config.inc.php';

# Initialize Template logic
serendipity_smarty_init();

# Fetch the 5 latest entries
$entries = serendipity_fetchEntries(null, true, 5);

# Parses the latest entries with the embedded template
$serendipity['template'] = 'embedded';
serendipity_printEntries($entries);

# Displays the latest entries
$serendipity['smarty']->display(serendipity_getTemplateFile('entries.tpl', 'serendipityPath'));
chdir('..');
?> 
Let me know if this works out for you.

Posted: Fri Jul 14, 2006 8:40 am
by Johan
Thanks for your help.
I've tried it and it works! Thanks!
Got a couple of problems...(I am not that experienced).

This is the http://www.xcalak.info/scripts/blog/index2.php contents:

<?php
chdir('blog'); // Or change this to the name of the directory where you installed s9y in!

# Include the s9y framework
include 'serendipity_config.inc.php';

# Initialize Template logic
serendipity_smarty_init();

# Fetch the 5 latest entries
$entries = serendipity_fetchEntries(null, true, 5);

# Parses the latest entries with the embedded template
$serendipity['template'] = 'embedded';
serendipity_printEntries($entries);

# Displays the latest entries
$serendipity['smarty']->display(serendipity_getTemplateFile('entries.tpl', 'serendipityPath'));
chdir('..');
?>

A. Error

http://www.xcalak.info/scripts/blog/index2.php produces the error:


Warning: chdir(): No such file or directory (errno 2) in /home/xcalak/public_html/scripts/blog/index2.php on line 2


If I comment out the line
chdir('blog'); // Or change this to the name of the directory where you installed s9y in!
then it seems to work.
Should I comment out this line?

B. HTML

The result of the entries.tpl is a page without <head>, <body> etc.
Should I add that code to the entries.tpl file?

C. Layout

I am having some trouble removing code from the http://www.xcalak.info/scripts/blog/tem ... ntries.tpl file. When I take out more then I have done now then I get errors. I have tried several times but it keeps on going wrong.

I would like it to look like this:

Sunday, July 2. 2006

Restaurant Report
Posted by: Cliff Evans
In: Reports From South Of Town
On: 04:37, 27 June 2006.


New building info
Posted by: Judy Hagmann
In: Building Casa Escondida
On: 08:09, June 26. 2006.

Could you please advise how to create the code for this.

D. Style sheet

I would like the index2.php result to look like the rest of the site.
Can I link it to the site style sheet or can I make a separate style sheet for this page within the embedded template structure?

E. Links

The links in the index2.php page point to the same window.
I am planning to include the index2.php in my main page by means of a small iframe. The result would be the weblog would appear in this small window instead of replacing the top page or go to a blank page. Is there a solution for this? (Can this be done in de style sheet?)


Thanks,

Hanno

Posted: Fri Jul 14, 2006 11:27 am
by jojje
I have a simular question about this.

I want to add one entry from one category on the static page that is set to be frontpage.


A solved this partly with this code in plugin_staticpage-tpl:

Code: Select all

{serendipity_fetchPrintEntries category=1 limit=1 use_hooks=0 template=entries_news.tpl}
Works great except that is is printed on all static pages.

Is there any easy way to solve this, to check if the static page is a frontpage before printing.

Posted: Fri Jul 14, 2006 12:22 pm
by garvinhicking
Hi!

The chdir() error happens because your index2.php file is already in the 'blog' directory, so it cannot switch to a subdirectory 'blog'. Either remove that chdir() call completely, or put in the full path to your blog there, that's right.

Code: Select all

[b]B. HTML[/b]

The result of the entries.tpl is a page without <head>, <body> etc.
Should I add that code to the entries.tpl file?
No, the embedding method actually expects, that your index2.php file is emitting all the HTML head and body / wrapping construct. Since you want to emit custom HTML, the PHP code only takes care of returning the entries itself; all the other HTML you should put in from your custom application.

If you prefer though, you could put it into the entries.tpl file, yes.
C. Layout

I am having some trouble removing code from the http://www.xcalak.info/scripts/blog/tem ... ntries.tpl file. When I take out more then I have done now then I get errors. I have tried several times but it keeps on going wrong.
This sounds like you're removing too much structural code from entries.tpl. You need to take care that all {if} and {foreach} structures are properly aligned and matched!
D. Style sheet

I would like the index2.php result to look like the rest of the site.
Can I link it to the site style sheet or can I make a separate style sheet for this page within the embedded template structure?
You could do both, yes. Since you need to emit the CSS sheet (as answered in the previous question), you are free to use whatever CSS you like.
E. Links

The links in the index2.php page point to the same window.
I am planning to include the index2.php in my main page by means of a small iframe. The result would be the weblog would appear in this small window instead of replacing the top page or go to a blank page. Is there a solution for this? (Can this be done in de style sheet?)
You cannot do this in a stylesheet. You would need to append "target=_blank" to all of your links in the <a> tag!

Best regards,
Garvin

Posted: Fri Jul 14, 2006 5:35 pm
by judebert
I think that about covers it, Johan. If you have any other questions, feel free to ask.

jojje, you can check whether the current page is the front page with the $startpage variable, thusly:

Code: Select all

{if $startpage}
{serendipity_fetchPrintEntries category=1 limit=1 use_hooks=0 template=entries_news.tpl}
{/if}

Posted: Sat Jul 15, 2006 11:31 am
by Johan
Hi,

I did everything and it works fine.
Little problem with the style sheet but I will check further...


More questions:

A. entry.tpl code

There is (a lot of) code in the entry.tpl which starts like this:

{if $is_single_entry and not $is_preview}

Can I delete that code? It doens't seem to do anything.
I deleted the test entries until one was left over but no change in the page. When I delete all the code after that point then I get the error:
Fatal error: Smarty error:
[in file:/home/xcalak/public_html/scripts/blog/templates/embedded/entries.tpl line 85]: syntax error: unclosed tag {foreach} (opened line 23). (Smarty_Compiler.class.php, line 317) in /home/xcalak/public_html/scripts/blog/bundled-libs/Smarty/libs/Smarty.class.php on line 1088


B. Date

It now shows the time only but I would like to have time and date.
How can I do that?

C. Time correction for users

The users will be in different time zones.
Is it possible to entern a time zone correction (like: -7 hours) for each user? Otherwise it seems like users are entering their stories in the middle of the night.



Thanks for your quick help!

Hanno

Posted: Mon Jul 17, 2006 10:49 am
by garvinhicking
Hi Johan!

Code: Select all

There is (a lot of) code in the entry.tpl which starts like this:

        {if $is_single_entry and not $is_preview}

Can I delete that code? It doens't seem to do anything.
I deleted the test entries until one was left over but no change in the page. When I delete all the code after that point then I get the error:
[i]Fatal error: Smarty error:
 [in file:/home/xcalak/public_html/scripts/blog/templates/embedded/entries.tpl line 85]: syntax error: unclosed tag {foreach} (opened line 23). (Smarty_Compiler.class.php, line 317) in /home/xcalak/public_html/scripts/blog/bundled-libs/Smarty/libs/Smarty.class.php on line 1088[/i]
This code is logical template formatting. It instructs your template to check variables for example. If you deleted the above IF-Construct, for example, it would tell the template to show the underlying block always, and not only when an entry is being fully viewed/previewd.

The other error message tells you that you removed code that leads to unbalanced logic.

Only delete things where you know what they do. ;-)
B. Date

It now shows the time only but I would like to have time and date.
How can I do that?
How do you currently print your time? Usually you can use "%m" or "%h" placeholders for minute / hours. The available placeholders are listed here: http://de3.php.net/strftime
C. Time correction for users

The users will be in different time zones.
Is it possible to entern a time zone correction (like: -7 hours) for each user? Otherwise it seems like users are entering their stories in the middle of the night.
No. You can only enter a timezone difference that globally applies to the blog, not to single users. For a multiple-user blog this might make sense - but it might also confuse users, who instead might prefer one central time, and that being the timezone of the server where people post in. No matter where a user comes from, the timzone in the server will always be the same, so in fact they would be entering their stories in the middle of the night, that's right. :)

Best regards,
Garvin