Blog Archive
4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 13, 2012 (RSS)
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)
Any help here much appreciated!
Shannon
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: [shannonr] Blog Archive
Hi Shannon,
It looks as if you have everything set up correctly on your date filter links, you just need to set allowSearch to true in your getRecords function and it should work.
I've also added an if statment (highlighted in blue) that will check if the date_year has been set in the url and added to the request array and if it hasn't, will change it to 2012.
Thanks!
It looks as if you have everything set up correctly on your date filter links, you just need to set allowSearch to true in your getRecords function and it should work.
Code
<?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."); }
//If date_year isn't set, set it to 2012
if(!@$_REQUEST['date_year']){
$_REQUEST['date_year'] = '2012';
}
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'loadUploads' => true,
'allowSearch' => true,
'orderBy' => 'createdDate DESC',
));
?>
I've also added an if statment (highlighted in blue) that will check if the date_year has been set in the url and added to the request array and if it hasn't, will change it to 2012.
Thanks!
Greg Thomas
PHP Programmer - interactivetools.com
PHP Programmer - interactivetools.com
Re: [greg] Blog Archive
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
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!
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
PHP Programmer - interactivetools.com