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
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 Perchpole - August 2, 2011
I've set-up a basic section in CMSB called "blog". It's set-up to output the records in a list - with 5 entries per page.
This is the basic code...
// load records
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'perPage' => '5',
'loadUploads' => '0',
'allowSearch' => '0',
));
//Loop Thru results
<?php foreach ($blogRecords as $record): ?>
<a name="<?php echo $record['num'] ?>" id="<?php echo $record['num'] ?>"></a>
<strong><?php echo $record['title'] ?></strong><br/>
<?php echo $record['content'] ?><br/>
<hr/>
<?php endforeach ?>
For each entry there's just a title and one or two paragraphs of text. Nothing more. For this reason there is no need to go to a detail page.
What I want to do is create a navigation widget for the home page so that readers can click on a link and jump straight to the related entry in the blog. You'll notice I've used named anchors next to the title of each record. I'll be able to use these in the links to line-up the correct entry on the page.
The trouble is, how do I factor in the page number?
Using the example code above we can see there will be 5 records perPage. So, if there were 7 blog entries in total, record numbers 7, 6, 5, 4 & 3 would be shown on the first page. Record numbers 1 and 2 will be on the second page.
If I want to link to record num 5 on the first page the link would be something like this...
./index.php?blog.php#5
However if I want to link to record num 2 it would be like this...
./index.php?blog.php?page=2#2
How do I generate a link that takes this into account and modifies the link code accordingly?
:0/
Perch
Re: [Perchpole] Blog Page Navigation - Early Thoughts
By Jason - August 2, 2011
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
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
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
Thanks, Jason.
:0)
Perch