Advertisement
jaideep06

custom sitemap

Nov 6th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. namespace RankMath\Sitemap\Providers;
  4.  
  5. defined( 'ABSPATH' ) || exit;
  6.  
  7. class Custom implements Provider {
  8.  
  9.     public function handles_type( $type ) {
  10.         return 'seo-glossary' === $type;
  11.     }
  12.  
  13.     public function get_index_links( $max_entries ) {
  14.         return [
  15.             [
  16.                 'loc'     => \RankMath\Sitemap\Router::get_base_url( 'seo-glossary-sitemap.xml' ),
  17.                 'lastmod' => '',
  18.             ]
  19.         ];
  20.     }
  21.  
  22.     public function get_sitemap_links( $type, $max_entries, $current_page ) {
  23.         $links = []; // Initialize the array to store the links
  24.  
  25.         $parent_permalink = get_permalink(457);
  26.         if ($parent_permalink) {
  27.             $links[] = [
  28.                 'loc'     => $parent_permalink,
  29.                 'lastmod' => get_post_modified_time('c', true, 457)
  30.             ];
  31.         }
  32.  
  33.         $pages = get_posts(array(
  34.             'posts_per_page' => -1,
  35.             'post_type'      => 'page', // Replace 'page' if you need another post type
  36.             'post_status'    => 'publish' // Ensure only published posts are included
  37.         ));
  38.  
  39.         foreach ($pages as $p) {
  40.             if ($p->post_parent == 457) {
  41.                 $links[] = [
  42.                     'loc'     => get_permalink($p), // Add the page's permalink
  43.                     'lastmod' => get_post_modified_time('c', true, $p) // Add last modified date in ISO 8601 format
  44.                 ];
  45.             }
  46.         }
  47.  
  48.         return $links;
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement