How to use Timeline for Wordpress archives

Basically, just read this post Timeline Archive View For WordPress and then do some improvement by following my article.
First, we don't want to generate a XML file every time, so make it generate one XML file and let the Timeline uses that XML file. Here is the code, put this code in the wordpress root, this is the modified version of the original one from Crickets Chirping:

if (empty($wp)) {
    require_once('wp-config.php');
    wp('feed=atom');
}
$more = 1;
$data = '<data>';
$my_query = new WP_Query('showposts=50');//change the number for showposts
//to how many post you want to show on the timeline.
 
while ($my_query->have_posts()){
	$my_query->the_post();
    $data .= '<event 
        start="';
        ob_start();
    	$data .= get_post_time('M d Y H:i:s \G\M\T', true);
    	ob_end_clean();
        $data .= '"
        isDuration="false"
        title="';
        ob_start();
        the_title_rss();
        $data .= ob_get_contents();
        ob_end_clean();
        $data .= '"
        link="';
        ob_start();
        permalink_single_rss();
        $data .= ob_get_contents();
        ob_end_clean();
        $data .= '">';
 
	ob_start();
	the_excerpt_rss(40, 1);
	$cool = ob_get_contents();
	ob_end_clean();
	$data .= str_replace('>','&gt;',str_replace('<', '&lt;',$cool));
	$data .= '</event>';
}
 
$data .= '</data>';
$fname = "timeline-xml.xml";//name of the file
$fhandle = fopen($fname,"w");
fwrite($fhandle,$data);
fclose($fhandle);

And that generate a XML file in the server. Make the Timeline API link to that XML file
Now we just want to run it every one hour(or what ever you think it's fit), do that by configure the cron job or using a fake cron script like WP-cron.


Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.

More information about formatting options

What is 15 + 8?
To combat spam, please solve the math question above.
Honey Pot that kill bots