Advertisement
drkskwlkr

Extract product and category URLs from OpenCart Google Sitemap feed module

Feb 19th, 2022 (edited)
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. /* List all product and category URLs for an OpenCart website using the standard Google Sitemap feed */
  2.  
  3. <?php
  4. $domain = "https://www.example.com/" ; // Replace with your actual domain name
  5. $base   = "index.php?route=feed/google_sitemap" ;
  6. $reqURL = $domain . $base ;
  7. $html   = @file_get_contents ($reqURL) ;
  8.  
  9. if($html === FALSE)
  10. {
  11.   echo '<h1>Please make sure that Google Sitemap Feed is active and the URL is correct</h1>' ;
  12.   die();
  13. }
  14.  
  15. $DOM  = new DOMDocument() ;
  16. $DOM->loadHTML($html) ;
  17.  
  18. /* Filter loc tags */
  19. $rows = $DOM->getElementsByTagName("loc") ;
  20.  
  21. $i = 0 ;
  22.  
  23. echo "<pre>\n" ;
  24.  
  25. while(is_object($url = $DOM->getElementsByTagName("url")->item($i)))
  26. {
  27.   foreach($url->childNodes as $url)
  28.   {
  29.     if($url->nodeName=='loc')
  30.     {
  31.       echo $url->nodeValue . PHP_EOL ;
  32.     }
  33.   }
  34.   $i++ ;
  35. }
  36. echo "</pre>\n" ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement