Page 1 of 1

Limiting the number of recent posts on external page.

Posted: Sun Oct 08, 2006 4:52 am
by spackler
I am using s9y on one of my sites to allow users to easily post news releases so I am trying to trim down the blog functionality. One of the things I am doing is posting the title/date of our entries to all pages on our site using the code below. I'm wondering if anyone would know how to limit the number that shows in the list?

I have a file in the template directory called myentries.tpl with the following code

Code: Select all

{serendipity_hookPlugin hook="entries_header"}


<div class="serendipity_entry">
    <ul>
    {foreach from=$entries item="entries"}
        {foreach from=$entries.entries item="entry"}
            <li><a href="{$entry.link}">{$entry.title}</a>
                <br />{$CONST.ON} {$entry.timestamp|@formatTime:DATE_FORMAT_ENTRY}</li>
        {/foreach}
    {/foreach}
    </ul>
</div>
<div class='serendipity_entryFooter' style="text-align: center">
{serendipity_hookPlugin hook="entries_footer"}</div>
and then I put this code into each external page:

Code: Select all

<?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 latest entries 
$entries = serendipity_fetchEntries(); 

# Parses the latest entries 
serendipity_printEntries($entries); 

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

Posted: Sun Oct 08, 2006 5:02 am
by azel
Go to your Administration screen and under the Administration -> Configuration -> Appearance and Options menu, change the number of posts you would like to appear on the front page.

Posted: Sun Oct 08, 2006 11:11 pm
by stm999999999
it is only an idea and I dont know if it works, but:

if you work with s9y-smarty:

Code: Select all

# Initialize Template logic 
serendipity_smarty_init();
perhaps it is the easyest way to fetch entrys by

Code: Select all

{serendipity_fetchPrintEntries template="my-entries.tpl" limit=10 noSticky="true"}
and for example: my-entries.tpl:

Code: Select all

{if $entries}

<ul>
    {foreach from=$entries item="dategroup"}
            {foreach from=$dategroup.entries item="entry"}
			<li class="static-entries">
        		({$dategroup.date|date_format:"%d.%m.%Y"}) <a href="{$entry.link}">{$entry.title|@default:$entry.id}</a>
<!--
            <div>
                {$entry.body|truncate:160:' ...'}
            </div>
 -->
			</li>
            {/foreach}
   {/foreach}
</ul>

{/if}
or your tpl-code

Posted: Sun Oct 08, 2006 11:16 pm
by azel
Whoops I guess I misread your post, spackler. Sorry! ^_^

Posted: Fri Oct 20, 2006 11:25 pm
by spackler
Thanks stm, I'm trying this out with no luck. Are you suggesting to replace my code with yours or add to it?

No problem Azel :) Thanks for replying.

Posted: Fri Oct 20, 2006 11:35 pm
by stm999999999
replace all after the smary_init with

Code: Select all

{serendipity_fetchPrintEntries template="my-entries.tpl" limit=10 noSticky="true"}
and then the

Code: Select all

{if $entries} 

<ul> 
    {foreach fr ...
in an file in your template-folder in my-entries.tpl

But, as I said, it could work. But I do not know, if. Here, I think, garvin must help out.

Posted: Fri Oct 20, 2006 11:49 pm
by spackler
thanks for the quick reply. no matter how I slice it it throws the error:

Parse error: parse error in .../html/fetchtest.php on line 123

line 123 is the line with

Code: Select all

{serendipity_fetchPrintEntries template="my-entries.tpl" limit=10 noSticky="true" }
on it

As a note. When you limit the entries on the front page that doesn't effect this extra external list - it is listing them all. One thing that I did note is that we have our Entries to display on frontpage set to 10 - but the Recent Entries plugin on the side is stopping at 7 - couldn't I connect that function to external pages?

Posted: Sun Oct 22, 2006 3:17 pm
by garvinhicking
Hi Spackler!

The Parse error is in your "fetchtest.php" file in line 123, not in the Smarty file at line 123!

What is inside the .php file at that line?

Best regards,
Garvin

Posted: Mon Oct 23, 2006 5:15 am
by spackler
Hi Garvin. That is from my fetchtest.php file no the my-entries.tpl, do I have them wrong?

Here is my code:

fetchtest.php

Code: Select all


<?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(); 

serendipity_fetchPrintEntries template="my-entries.tpl" limit=10 noSticky="true"
chdir('..'); 
?>
my-entries.tpl

Code: Select all

{if $entries} 

<ul> 
    {foreach from=$entries item="dategroup"} 
            {foreach from=$dategroup.entries item="entry"} 
         <li class="static-entries"> 
              ({$dategroup.date|date_format:"%d.%m.%Y"}) <a href="{$entry.link}">{$entry.title|@default:$entry.id}</a> 
<!-- 
            <div> 
                {$entry.body|truncate:160:' ...'} 
            </div> 
 --> 
         </li> 
            {/foreach} 
   {/foreach} 
</ul> 

{/if} 
Thanks for working on this for me, I think it would be very useful feature of the blog!

Posted: Mon Oct 23, 2006 11:22 am
by garvinhicking
Hi!

Yes, this is wrong :)

You mixed Smarty Code into your PHP file, which is not what it's meant to be. :) I just see that stm9x9 got you on that way, so just forget it and use this fetchtest.php:

Code: Select all


<?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(); 

$e = serendipity_fetchEntries(null, true, 10, false, false, 'timestamp DESC', '', false, true);
serendipity_printEntries($e);

$serendipity['smarty']->display(serendipity_getTemplateFile('my-entries.tpl', 'serendipityPath'));
chdir('..'); 
?>
The code you previously had in there is only meant to be containde within .tpl files.

HTH,
Garvin

Posted: Fri Oct 27, 2006 7:53 pm
by spackler
works perfect!

THANK YOU ALL!