Limiting the number of recent posts on external page.

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Limiting the number of recent posts on external page.

Post 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.
azel
Regular
Posts: 265
Joined: Thu Apr 21, 2005 4:28 am
Contact:

Post 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.
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

Post 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
Ciao, Stephan
azel
Regular
Posts: 265
Joined: Thu Apr 21, 2005 4:28 am
Contact:

Post by azel »

Whoops I guess I misread your post, spackler. Sorry! ^_^
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Post 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.
stm999999999
Regular
Posts: 1531
Joined: Tue Mar 07, 2006 11:25 pm
Location: Berlin, Germany
Contact:

Post 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.
Ciao, Stephan
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Post 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?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# 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/
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Post 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!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# 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/
spackler
Regular
Posts: 27
Joined: Fri Aug 19, 2005 8:13 pm
Location: Milwaukee
Contact:

Post by spackler »

works perfect!

THANK YOU ALL!
Post Reply