Linking to specific blog posts

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 1, 2010   (RSS)

Re: [wadeos] Linking to specific blog posts

By Damon - February 24, 2010

Hi,

Do you have an Author section setup in CMS Builder or are you using User Accounts for authors?

Can you post the code you have so far so I can take a look?
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] Linking to specific blog posts

By wadeos - February 24, 2010

Hi Damon,

I have created a blog in section editor and within that blog have created a list field with all the Authors names. So when they add a new entry they just click on the drop down list and pick their name.


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/home/nzph/public_html/cmsAdmin/lib/viewer_functions.php";

list($ridersblogRecords, $ridersblogMetaData) = getRecords(array(
'tableName' => 'ridersblog',
'perPage' => '7',
));

?>
<?php
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);

return $output;
}
?>

<!-- blog left column -->
<div id="LC_blog">

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Rider's Blog</h1>
<?php foreach ($ridersblogRecords as $record): ?>
<p span class="headline_blog"><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></span>
<p><?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?></p>
<p><?php echo $record['author'] ?></p>

<!-- For date formatting codes see: http://www.php.net/date -->
<p><?php echo maxWords($record['content'], 100); ?> . . . <a href="<?php echo $record['_link'] ?>">Read More</a></p>

<br/>


<hr size="1" noshade="noshade"/>
<?php endforeach; ?>

<?php if ($ridersblogMetaData['invalidPageNum']): ?>
Results page '<?php echo $ridersblogMetaData['page']?>' not found, <a href="<?php echo $ridersblogMetaData['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/><br/>
<?php elseif (!$ridersblogRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->


<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->
<?php if ($ridersblogMetaData['prevPage']): ?>
<a href="<?php echo $ridersblogMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

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

<?php if ($ridersblogMetaData['nextPage']): ?>
<a href="<?php echo $ridersblogMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>
<!-- /STEP3: Display Page Links -->
</div>
<!-- end blog left column -->

<!-- blog right column -->
<div id="RC_blog">
<p span class="rightcol_title">AUTHORS</span>
<p>View blogs by Author
<a href="#">Author 1</a><br />
<a href="#">Author 2</a><br />
<a href="#">Author 3</a><br />
<a href="#">Author 4</a><br />
</p>

</div>
<!-- end blog right column -->

Re: [wadeos] Linking to specific blog posts

By Damon - February 26, 2010

You could change this code:
<a href="#">Author 1</a><br />
<a href="#">Author 2</a><br />
<a href="#">Author 3</a><br />
<a href="#">Author 4</a><br />

To this:
<a href="./blog.php?author=Author 1">Author 1</a><br />
<a href="./blog.php?author=Author 2">Author 2</a><br />
<a href="./blog.php?author=Author 3">Author 3</a><br />
<a href="./blog.php?author=Author 4">Author 4</a><br />

This would display only the blog post by the author you linked from.

You could also use this on the page to show the name of the author that was in the query string:
<?php echo @$_GET["author"]; ?>

Give that a try and let me know how you make out.
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] Linking to specific blog posts

By wadeos - March 1, 2010

Thanks Damon, will have a go and get back to you if I get stuck.