Kdo bi mi lahko pomagal?
Namreč začel sem delati na kodi, ki sem jo objavil nad tem postom (link) in v loop:
//loop over each link and add it to the sitemap file
foreach ($currentSitemapPageRows as $key => $row) {
$final_url = $SERVER_NAME . fixSymbols(getUrlFriendlyString($row{'description'}));
$tutTag = $root->appendChild(
$xmlDoc->createElement("url"));
$tutTag->appendChild(
$xmlDoc->createElement("loc", htmlentities($final_url)));
$tutTag->appendChild(
$xmlDoc->createElement("priority", "0.5"));
}
...bi želel dodati tole:
<xhtml:link rel="alternate" hreflang="en" href="http://www.example.com/english/" />
<xhtml:link rel="alternate" hreflang="de" href="http://www.example.com/deutsch/" />
Uspelo mi je dodati samo eno vrstico s to kodo:
$langEn = $tutTag->appendChild(
$xmlDoc->createElement("xhtml:link")); // returns <xhtml:link/>
$tutTag = $langEn->appendChild(
$xmlDoc->createAttribute("rel"))->appendChild(
$xmlDoc->createTextNode("alternate"));
$tutTag = $langEn->appendChild(
$xmlDoc->createAttribute("hreflang"))->appendChild(
$xmlDoc->createTextNode("en"));
$tutTag = $langEn->appendChild(
$xmlDoc->createAttribute("href"))->appendChild(
$xmlDoc->createTextNode("http://www.example.com/english/"));
Če pa dodam še za "de":
$langDe = $tutTag->appendChild(
$xmlDoc->createElement("xhtml:link")); // returns <xhtml:link/>
$tutTag = $langDe->appendChild(
$xmlDoc->createAttribute("rel"))->appendChild(
$xmlDoc->createTextNode("alternate"));
$tutTag = $langDe->appendChild(
$xmlDoc->createAttribute("hreflang"))->appendChild(
$xmlDoc->createTextNode("de"));
$tutTag = $langDe->appendChild(
$xmlDoc->createAttribute("href"))->appendChild(
$xmlDoc->createTextNode("http://www.example.com/deutsch/"));
Pa se pojavi ta napaka:
Fatal error: Call to a member function appendChild() on a non-object
Help wanted!