melissa_boyle Posted January 31, 2014 Share Posted January 31, 2014 Hi Guys, I have used the below code to create an archive on blog stories. This works fine with all stories in the child directory to blog, however when I put them in the relevant folders eg 2014 > 01 > blogstory it doesn't seem to pull them through. Does anyone have any ideas, any help would be greatly appreciated. Thanks, Melissa <?php $channel = $pages->get("/blog/");$startYear = date("Y"); // this year$endYear = 2009; // or whenever you want it to end$now = time(); for($year = $startYear; $year >= $endYear; $year--) { for($month = 12; $month > 0; $month--) { $startTime = strtotime("$year-$month-01"); // 2011-12-01 example if($startTime > $now) continue; // don't bother with future dates if($month == 12) $endTime = strtotime(($year+1) . "-01-01"); else $endTime = strtotime("$year-" . ($month+1) . "-01"); $entries = $channel->children("blog_date>=$startTime, blog_date<$endTime"); // or substitute your own date field $date = date("F, Y",$startTime); $url = "/blog/" . date("Y",$startTime) . "/" . date("m",$startTime); $count = count($entries); if($count > 0) echo "<a href='$url'>$date (" . $count . ")</a><br>"; // output the month and count }}?> Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2014 Share Posted January 31, 2014 Hi Melissa, Just wanted to make sure you've seen this module: http://modules.processwire.com/modules/process-date-archiver/ Not sure if it behaves exactly the way you want, but if it does, it might save you re-inventing. Link to comment Share on other sites More sharing options...
melissa_boyle Posted February 3, 2014 Author Share Posted February 3, 2014 Hi Adrian, I have seen this however when the blog posts archive into the folders the archive code I have used above can't seem to find them obviously because they are within folders within /blog. I am unsure of how to implement this to allow it to work. I have tried finding the blogposts by template but this doesn't seem to work. Thanks, Melissa Link to comment Share on other sites More sharing options...
Wanze Posted February 3, 2014 Share Posted February 3, 2014 Hi Melissa, $channel = $pages->get("/blog/"); $entries = $channel->children("blog_date>=$startTime, blog_date<$endTime"); // or substitute your own date field If I understand your question right, the problem is that you are searching for blog-posts only for children of the /blog/ page. Try to search side-wide with with your blog template: $entries = $pages->find("template=blog,blog_date>=$startTime,blog_date<$endTime"); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now