-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml.php
51 lines (38 loc) · 1.36 KB
/
xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/*
Template Name: XML
*/
query_posts('orderby=rand&showposts=1&category_name=Manifiesto');
if (have_posts()) {
while (have_posts()) {
the_post();
$title = get_the_title();
$date = get_the_date();
$author = get_the_author();
$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", "", $content);
$content = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "", $content);
$excerpt = get_the_excerpt();
$excerpt = preg_replace("/<img[^>]+\>/i", "", $excerpt);
$excerpt = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "", $excerpt);
}
}
// Set the excerpt type to be XML, so that the browser will recognise it as XML.
header( "content-type: application/xml; charset=ISO-8859-15" );
// "Create" the document.
$xml = new DOMDocument( "1.0", "ISO-8859-15" );
// Create some elements.
$xml_album = $xml->createElement( "Post" );
$xml_track = $xml->createElement( "Title", $title );
$xml_album->appendChild( $xml_track );
$xml_track = $xml->createElement( "Author", $author );
$xml_album->appendChild( $xml_track );
$xml_track = $xml->createElement( "Date", $date );
$xml_album->appendChild( $xml_track );
$xml_track = $xml->createElement( "Content", str_replace('[…]', '', $excerpt) );
$xml_album->appendChild( $xml_track );
//$xml_album->appendChild( $xml_track );
$xml->appendChild( $xml_album );
// Parse the XML.
print $xml->saveXML();
?>