Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Created January 2, 2014 18:50
Show Gist options
  • Select an option

  • Save tcelestino/8224371 to your computer and use it in GitHub Desktop.

Select an option

Save tcelestino/8224371 to your computer and use it in GitHub Desktop.
<?php
ob_start();
if(!function_exists("do_action")) :
header('content-type: text/xml');
include_once('../../../../wp-config.php');
endif;
$xml = array();
$xml[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
$xml[] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
$xml[] = "<lista>";
$front_posts = get_posts('category_name=novidades&numberposts=1&orderby=post_date');
foreach($front_posts as $post) {
setup_postdata($post);
$xml[] = '<elemento id="'.$post->ID.'">';
$xml[] = '<chamada><![CDATA['.get_the_title().']]></chamada>';
$thumb = '';
$img_src = get_front_image();
if($img_src) $thumb = get_photo_thumb($img_src, 150, 105, true);
if(!$thumb) $thumb = '';
ob_start();
the_content();
$content = ob_get_contents();
ob_end_clean();
ob_start();
the_excerpt();
$excerpt = ob_get_contents();
ob_end_clean();
$xml[] = '<foto>'.$thumb.'</foto>';
$xml[] = '</elemento>';
}
$xml[] = "</lista>";
echo implode("\n", $xml);
$content = ob_get_contents();
ob_end_clean();
echo $content;
if(file_exists(dirname(__FILE__)."/novidades.xml")) :
$fp = fopen(dirname(__FILE__)."/novidades.xml", 'w');
fwrite($fp, $content);
fclose($fp);
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment