Blog: limiting number of posts per page

5 posts by 2 authors in: Forums > CMS Builder
Last Post: May 22, 2009   (RSS)

Hi, there.

I'm putting together a blog using CMSB: http://www.yallaf1.com/blog.php.

The first page of this section only needs to show the five most recent posts. Clicking on a headline link - for, say, http://www.yallaf1.com/blogDetail.php?1 - should only show a single post.

Does anyone know how to set up the blog - or any other multi-page section, for that matter - so that I can limit the number of (a) headlines that appear and (b) the number of posts that appear, whether it's five or only one?

Thanks!
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Blog: limiting number of posts per page

By Damon - May 22, 2009

Hi Nigel,

To limit the number of posts that appear in an index use this code in to top part of your page:

'perPage' => '5',

Next, it appears that your blog.php and blogDetail.php pages are almost the indentical.

Does the blogDetail.php have a foreach loop for the content? It shouldn't so this would explain the additional article on the page.

Use the Code Generator for the blog to generate single page code to confirm the correct code.

To make it easy to check your blog post links are linking to the right page, try adding the "title" to the Filename Fields:
Admin > Section Editors > click modify for the Blog seciton, then click on the Viewer Urls.

I hope this helps.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Blog: limiting number of posts per page

Thanks, Damon. That works perfectly: http://www.yallaf1.com/blog.php.

Please can you point me to a tutorial that explains how I link to the rest of the posts? i.e. the index page for earlier articles.

regards,
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Blog: limiting number of posts per page

By Damon - May 22, 2009

Hi Nigel,

The best way to link to earlier articles is to setup prev and next links at the bottom of the blog index page.

When you generate code for the Blog section index (List page), in the View Options under "How Many", select the radio button for Show "5" records per page with prev & next page links.

This will generate the code to use. This is the part of the code that will generate the previous and next page links:

<?php if ($blogMetaData['prevPage']): ?>
<a href="<?php echo $blogMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $blogMetaData['page'] ?> of <?php echo $blogMetaData['totalPages'] ?> -

<?php if ($blogMetaData['nextPage']): ?>
<a href="<?php echo $blogMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>


Let me me know how this works out for you.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Blog: limiting number of posts per page

Great stuff! Thanks for your help.
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net