Jump to content

Blog archive date not pulling from folder


melissa_boyle
 Share

Recommended Posts

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

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

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"); 
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...