Blog Archive

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 13, 2012   (RSS)

By shannonr - November 12, 2012

Hi
Sorry if this had been done (to death no doubt), I couldn't quite get there from searching this forum.
Anyway, I need to have my blog page showing only this years' posts (i.e. all posts from 2012), and then showing a list on the right of posts archived by year.
I have got the list to appear (using suggestion by Deborah on this forum), but its loading all posts - I need to figure out how to filter them to only show that year's content (also when the page first loads it needs to just be this current year's posts).

Here is the code on the page: (simplified version of http://www.space-alchemy.com/2012/blog.php)

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

$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/spaceal/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => false,
'orderBy' => 'createdDate DESC',
));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Space Alchemy</title>
</head>
<body>
<div id="leftColText">
<h2>Blog</h2>
<?php foreach ($blogRecords as $record): ?>
Title: <?php echo htmlencode($record['title']) ?><br/>
Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/><!-- For date formatting codes see: http://www.php.net/date -->
Content: <?php echo htmlencode($record['content']) ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

<?php foreach ($record['uploads'] as $index => $upload): ?>
Upload Url: <?php echo $upload['urlPath'] ?><br/>

Thumb Url: <?php echo $upload['thumbUrlPath'] ?><br/><br/>
Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>

Image Tags:<br/>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
info1 (Title) : <?php echo htmlencode($upload['info1']) ?><br/>
info2 (Caption) : <?php echo htmlencode($upload['info2']) ?><br/><br/>
<hr/>
<?php endforeach ?>
<?php endforeach ?>
</div>

<!----------------------------- archive list ----------->

<div id="rightColText">
<h2>Blog Menu</h2>
<?php
$query = "SELECT DATE_FORMAT(date, '%Y') as Year, YEAR(date) as year FROM cms_blog GROUP BY Year ORDER BY createdDate";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)):
?>

<a href="blog.php?date_year=<?php echo $record['year'] ?>"><?php echo $record['Year']; ?></a><br/>

<?php endwhile ?>
</div>
</body>


Any help here much appreciated!

Shannon

Re: [greg] Blog Archive

By shannonr - November 12, 2012

Hi Greg - thanks for your reply. Unfortunately I'm not getting any filtering at all - all the posts are showing up regardless of of which year is selected...any ideas? I had createdDate before and I've now changed it to date, still no joy...

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


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/spaceal/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
if(!@$_REQUEST['date_year']){
$_REQUEST['date_year'] = '2012';
}

// load records from 'blog'
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => true,
'orderBy' => 'date DESC',
));
?>

<?php
// get list of unique months and years with articles ----
$query = "SELECT DATE_FORMAT(date, '%Y') as Year, YEAR(date) as year FROM cms_blog GROUP BY Year ORDER BY date";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)):
?>

<a href="blog.php?date_year=<?php echo $record['year'] ?>"><?php echo $record['Year']; ?></a><br/>

<?php endwhile ?>

Re: [shannonr] Blog Archive

By gregThomas - November 13, 2012

Hi,

I've done some testing and I can't work out why it's not filtering anything at all, for example:

http://www.space-alchemy.com/2012/blog.php?num=5463557

should stop the page returning anything.

Please could you fill out a second level support request for me?


https://www.interactivetools.com/support/email_support_form.php


Then I can take a closer look at what could be causing the issue.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com