Wpms html sitemap

A WordPress Multisite (WPMS) HTML sitemap is a file that lists all the pages, posts, and categories within a WPMS network. Here's a step-by-step guide to create an HTML sitemap for your WPMS:

Method 1: Using a Plugin

  1. Install and activate the "WP Sitemap Page" plugin.
  2. Go to Settings > WP Sitemap Page and configure the plugin settings.
  3. Choose the type of sitemap you want to generate (e.g., HTML, XML, or both).
  4. Set the sitemap title, description, and other options as desired.
  5. Click "Save Changes" to generate the sitemap.

Method 2: Using a Theme Function

  1. Create a new PHP file in your theme's directory (e.g., sitemap.php).
  2. Add the following code to the file:
    <?php
    function wpms_sitemap() {
    $sitemap = '<ul>';
    $sites = get_sites();
    foreach ( $sites as $site ) {
     $sitemap.= '<li><a rel="nofollow" target="_blank" href="'. get_home_url( $site->blog_id ). '">'. $site->blog_name. '</a>';
     $pages = get_pages( array( 'site_id' => $site->blog_id ) );
     foreach ( $pages as $page ) {
       $sitemap.= '<ul>';
       $sitemap.= '<li><a rel="nofollow" target="_blank" href="'. get_permalink( $page->ID ). '">'. $page->post_title. '</a>';
       $sitemap.= '</li>';
       $sitemap.= '</ul>';
     }
     $categories = get_categories( array( 'site_id' => $site->blog_id ) );
     foreach ( $categories as $category ) {
       $sitemap.= '<ul>';
       $sitemap.= '<li><a rel="nofollow" target="_blank" href="'. get_category_link( $category->term_id ). '">'. $category->name. '</a>';
       $sitemap.= '</li>';
       $sitemap.= '</ul>';
     }
     $sitemap.= '</li>';
    }
    $sitemap.= '</ul>';
    echo $sitemap;
    }
    add_action( 'wp_footer', 'wpms_sitemap' );
    ?>
  3. Add the following code to your theme's functions.php file:
    function add_sitemap_to_footer() {
    wpms_sitemap();
    }
    add_action( 'wp_footer', 'add_sitemap_to_footer' );
  4. Save the changes and visit your site's footer to see the sitemap.

Method 3: Using a Custom Page

  1. Create a new page in your WPMS network (e.g., sitemap).
  2. Add the following code to the page content:
    <ul>
    <?php
    $sites = get_sites();
    foreach ( $sites as $site ) {
    ?>
     <li><a rel="nofollow" target="_blank" href="<?php echo get_home_url( $site->blog_id );?>"><?php echo $site->blog_name;?></a>
       <ul>
         <?php
         $pages = get_pages( array( 'site_id' => $site->blog_id ) );
         foreach ( $pages as $page ) {
          ?>
           <li><a rel="nofollow" target="_blank" href="<?php echo get_permalink( $page->ID );?>"><?php echo $page->post_title;?></a></li>
           <?php
         }
         $categories = get_categories( array( 'site_id' => $site->blog_id ) );
         foreach ( $categories as $category ) {
          ?>
           <li><a rel="nofollow" target="_blank" href="<?php echo get_category_link( $category->term_id );?>"><?php echo $category->name;?></a></li>
           <?php
         }
        ?>
       </ul>
     </li>
     <?php
    }
    ?>
    </ul>
  3. Save the changes and visit the sitemap page to see the list of sites, pages, and categories.

Remember to customize the sitemap code to fit your specific needs and design.