Zadejte hledaný výraz...
Jakub Glos
Webtrh.cz
Vývoj webových stránek na WordPressu a proklientský přístup pro freelancery
Třídenní infromacemi nabitý prezenční + online kurz v Praze od Webtrhu pouze za 2 871 Kč
Více informací

Přidání obrázku do rss

Michales
verified
rating uzivatele
(5 hodnocení)
15. 1. 2016 18:19:45
Dobrý den,
chtěl bych se zeptat jakým způsobem, pokud to lze přidat obrázek do rss.
Tzn. pokud mám boxík na seznamu aby v náhledu byl vidět obrázek.
Využívám následující script:
$mysql_host = 'localhost'; //host
$mysql_username = ''; //username
$mysql_password = ''; //password
$mysql_database = ''; //db
header('Content-Type: text/xml; charset=utf-8', true); //set document header content type to be XML
$xml = new DOMDocument("1.0", "UTF-8"); // Create new DOM document.
//create "RSS" element
$rss = $xml->createElement("rss");
$rss_node = $xml->appendChild($rss); //add RSS element to XML node
$rss_node->setAttribute("version","2.0"); //set RSS version
//set attributes
$rss_node->setAttribute("xmlns:dc","http://purl.org/dc/elements/1.1/"); //xmlns:dc (info http://j.mp/1mHIl8e )
$rss_node->setAttribute("xmlns:content","http://purl.org/rss/1.0/modules/content/"); //xmlns:content (info http://j.mp/1og3n2W)
$rss_node->setAttribute("xmlns:atom","http://www.w3.org/2005/Atom");//xmlns:atom (http://j.mp/1tErCYX )
//Create RFC822 Date format to comply with RFC822
$date_f = date("D, d M Y H:i:s T", time());
$build_date = gmdate(DATE_RFC2822, strtotime($date_f));
//create "channel" element under "RSS" element
$channel = $xml->createElement("channel");
$channel_node = $rss_node->appendChild($channel);
//a feed should contain an atom:link element (info http://j.mp/1nuzqeC)
$channel_atom_link = $xml->createElement("atom:link");
$channel_atom_link->setAttribute("href","http://localhost"); //url of the feed
$channel_atom_link->setAttribute("rel","self");
$channel_atom_link->setAttribute("type","application/rss+xml");
$channel_node->appendChild($channel_atom_link);
//add general elements under "channel" node
$channel_node->appendChild($xml->createElement("title", "Country music")); //title
$channel_node->appendChild($xml->createElement("description", "To nejlepší s country muziky")); //description
$channel_node->appendChild($xml->createElement("link", "http://example.com")); //website link
$channel_node->appendChild($xml->createElement("language", "en-us")); //language
$channel_node->appendChild($xml->createElement("lastBuildDate", $build_date)); //last build date
$channel_node->appendChild($xml->createElement("generator", "PHP DOMDocument")); //generator
//Fetch records from the database
//connect to MySQL - mysqli(HOST, USERNAME, PASSWORD, DATABASE);
$mysqli = new mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database);
//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
//MySQL query, we pull records from site_contents table
$results = $mysqli->query("SELECT interprets.id as cover, albums.id, name, Album, Year, vlozeni, Albumartist FROM interprets LEFT JOIN albums ON interprets.id = albums.interpret ORDER BY albums.id DESC LIMIT 10");
if($results){ //we have records
while($row = $results->fetch_object()) //loop through each row
{
$item_node = $channel_node->appendChild($xml->createElement("item")); //create a new node called "item"
$title_node = $item_node->appendChild($xml->createElement("title", $row->Album .' - '.$row->name.' - '.$row->Year)); //Add Title under "item"
$link_node = $item_node->appendChild($xml->createElement("link", "http://example.com/show.php?album=". $row->id)); //add link node under "item"
$image_node = $item_node->appendChild($xml->createElement("image", "http://example.com/albums/". $row->cover."/".$row->Album.".jpg")); //add link node under "item"
//Unique identifier for the item (GUID)
$guid_link = $xml->createElement("guid", "http://example.com/show.php?album=". $row->id);
$guid_link->setAttribute("isPermaLink","false");
$guid_node = $item_node->appendChild($guid_link);
//create "description" node under "item"
$description_node = $item_node->appendChild($xml->createElement("description"));
//fill description node with CDATA content
$description_contents = $xml->createCDATASection(htmlentities($row->Albumartist));
$description_node->appendChild($description_contents);
//Published date
$date_rfc = gmdate(DATE_RFC2822, strtotime($row->vlozeni));
$pub_date = $xml->createElement("pubDate", $row->vlozeni);
$pub_date_node = $item_node->appendChild($pub_date);
}
}
echo $xml->saveXML();
?>
Zkoušel jsem tam obrázek přidat ale nezobrazí se. Lze to nějakým způsobem udělat?
Výsledek je možné vidět zde:
Country music…
Moc děkuji za pomoc
15. 1. 2016 18:19:45
https://webtrh.cz/diskuse/pridani-obrazku-do-rss/#reply1166545
i-PRESS
verified
rating uzivatele
(2 hodnocení)
15. 1. 2016 18:50:33
Jen tak po letmém pohledu, špatně tam skládáte tu cestu. V elementu image máte http://country.funsite.cz/albums/326/If%20You%20(EP).jpg, ale v detailu desky je /album/...
15. 1. 2016 18:50:33
https://webtrh.cz/diskuse/pridani-obrazku-do-rss/#reply1166544
Michales
verified
rating uzivatele
(5 hodnocení)
15. 1. 2016 18:52:39
Napsal i-PRESS;1257385
Jen tak po letmém pohledu, špatně tam skládáte tu cestu. V elementu image máte http://country.funsite.cz/albums/326/If%20You%20(EP).jpg, ale v detailu desky je /album/...
Toho jsem si nevšiml, děkuji.
Ovšem jak se zdá tak to nepomohlo.
15. 1. 2016 18:52:39
https://webtrh.cz/diskuse/pridani-obrazku-do-rss/#reply1166543
i-PRESS
verified
rating uzivatele
(2 hodnocení)
15. 1. 2016 19:15:42
Aha, toto platí pouze pro samotný feed. V Item to šlo nějak obejít pomocí media:thumbnail, ale mám obavu, že to moc podporováno nebude..
15. 1. 2016 19:15:42
https://webtrh.cz/diskuse/pridani-obrazku-do-rss/#reply1166542
Michales
verified
rating uzivatele
(5 hodnocení)
15. 1. 2016 19:21:16
Napsal i-PRESS;1257392
Aha, toto platí pouze pro samotný feed. V Item to šlo nějak obejít pomocí media:thumbnail, ale mám obavu, že to moc podporováno nebude..
Dobře, díky moc.
15. 1. 2016 19:21:16
https://webtrh.cz/diskuse/pridani-obrazku-do-rss/#reply1166541
Pro odpověď se přihlašte.
Přihlásit