XML Feed - Monthly Archives of Wordpress Articles


/ Published in: PHP
Save to your folder(s)

In case you need to create your own listing of the last # of trailing months of Archived Wordpress Articles. This one is being used to pull the info onto a Magento page.


Copy this code and paste it in your HTML
  1. <?php
  2. $curyear = date("Y");
  3. $curdate = array();
  4. $totalmonths = 24;
  5.  
  6. for ( $i=0; $i<$totalmonths; $i++ ) {
  7. $newmonth = date("m",strtotime("-$i Months"));
  8.  
  9. if ($newmonth == '12' && date("m") != '12')
  10. $curyear = $curyear-1;
  11.  
  12. $curdate[$i] = array("mnum" => $newmonth, "ynum" => $curyear);
  13. }
  14.  
  15. $output = "
  16. <?xml version=\"1.0\">
  17. <blocks>
  18. <block title=\"Article Archive\">
  19. <links>
  20. ";
  21. for ( $i=0; $i<$totalmonths; $i++ )
  22. {
  23. $output .= "<link target=\"http://www.outdoorresearchverticulture.com/{$curdate[$i]['ynum']}/".$curdate[$i]['mnum']."/?ec3_listing=disable\">". strftime("%B, %Y",strtotime($curdate[$i]['mnum']."/1/".$curdate[$i]['ynum']))." </link>
  24. ";
  25. }
  26.  
  27.  
  28. $output .= "
  29. </links>
  30. </block>
  31. </blocks>";
  32. header("Content-Type: application/rss+xml");
  33. echo $output;
  34.  
  35. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.