Blog Page Navigation - Early Thoughts

6 posts by 2 authors in: Forums > CMS Builder
Last Post: August 3, 2011   (RSS)

By Perchpole - August 1, 2011

Hello, All

My new client has asked me to incorporate a particular style of blog into their new CMSB site. They want to post regular updates in the form of a continuous blog-roll. The content would appear as separate entries on a continually evolving list, paginated with around 10 entries per page. There would be no detail pages.

The question is, how would I go about developing the naviagtion for such a system?

Unlike normal links - which would jump straight to the detail page - I need to pick out an entry on a paginated list. The link would be something like this...

./index.php?category=n&page=n#anchor

There are three elements to the link.

The category - which is straight forward.

The anchor - which could be the $record['num'].

The only issue is the page! How on earth do I work out the page number?

I'm guessing there's a way to work out the total number of pages then divide it by the MySQL LIMIT value - and then something else...!

Has anyone got any advice?

:0/

Perch

Re: [Perchpole] Blog Page Navigation - Early Thoughts

By Jason - August 2, 2011

Hi Perch,

Here is a possible solution. For your navigation, return a list of all your blog entries like this:

// load records
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => '0',
'allowSearch' => '0',
));


Then, you can use a counter to increment a "page" variable every X records, X being the number of records per page being shown on your blog page. You could then output your navigation list like this:

<?php
$perPage = 5;
$recordCount = 0;
$currentPage = 1;
?>
<?php foreach ($blogRecords as $record): ?>
<?php

if (++$recordCount % $perPage == 0) { $currentPage ++; }

?>
<a name="./index.php?blog.php?page=<?php echo $currentPage;?>#<?php echo $recordNum;?>">
<strong><?php echo $record['title'] ?></strong>
</a>

<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Blog Page Navigation - Early Thoughts

By Perchpole - August 2, 2011

Hi, Jason -

This is great. Thanks.

Just one issue. The counter seems to be out by 1 place. The 5th record should be the last item on the first page - but the link sends it to page 2!

:oS

Perch

Re: [Perchpole] Blog Page Navigation - Early Thoughts

By Jason - August 3, 2011

Hi,

Yes, you're right, try this change:

<?php
$perPage = 5;
$recordCount = 0;
$currentPage = 1;
?>
<?php foreach ($blogRecords as $record): ?>
<?php

if ((++$recordCount % ($perPage + 1)) == 0) { $currentPage ++; }

?>
<a name="./index.php?blog.php?page=<?php echo $currentPage;?>#<?php echo $recordNum;?>">
<strong><?php echo $record['title'] ?></strong>
</a>

<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Blog Page Navigation - Early Thoughts

By Perchpole - August 3, 2011

Brilliant!

Thanks, Jason.

:0)

Perch