Чтобы сделать это из PHP, сделайте это так:
- Получить все сообщения, помеченные
publish
из базы данных.
- Экспорт их в массив с помощью следующей функции array2xml:
.
<code><?php
function array2xml($array, $name='array', $standalone=TRUE, $beginning=TRUE)
{
global $nested;
if ($beginning)
{
if ($standalone) header("content-type:text/xml;charset=utf-8");
$output .= '<'.'?'.'xml version="1.0" encoding="UTF-8"'.'?'.'>' . PHP_EOL;
$output .= '<' . $name . '>' . PHP_EOL;
$nested = 0;
}
// This is required because XML standards do not allow a tag to start with a number or symbol, you can change this value to whatever you like:
$ArrayNumberPrefix = 'ARRAY_NUMBER_';
foreach ($array as $root=>$child)
{
if (is_array($child))
{
$output .= str_repeat(" ", (2 * $nested)) . ' <' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>' . PHP_EOL;
$nested++;
$output .= array2xml($child,NULL,NULL,FALSE);
$nested--;
$output .= str_repeat(" ", (2 * $nested)) . ' </' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>' . PHP_EOL;
}
else
{
$output .= str_repeat(" ", (2 * $nested)) . ' <' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '><![CDATA[' . $child . ']]></' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>' . PHP_EOL;
}
}
if ($beginning)
$output .= '</' . $name . '>';
return $output;
}
//connect to database and select database (edit yourself)
mysql_connect("localhost", "username", "password");
mysql_select_db("databasename");
//Get all posts whose status us published.
$result = mysql_query("SELECT * FROM wp_posts WHERE post_status = 'publish'");
while($row = mysql_fetch_assoc($result))
$posts[] = $row;
//convert to array and print it on screen:
echo "<pre>";
echo htmlentities(array2xml($posts, 'posts', false));
echo "
";
?>