• I mainly use Pages (not Posts) and wanted a way to exclude Pages by the ID of their parent. Since Google XML Sitemaps didn’t have this feature built in, I implemented it myself. I’m here to share the simple code.

    Starting Line 1762 of sitemap-core.php, insert the following block:

    foreach ($excludes as $exclude)
    {
        $children = get_pages(array('child_of' => $exclude));
    
        foreach ($children as $child)
            $exChildren[] = $child->ID;
    }

    Then at Line 1781, insert:

    if (is_array($exChildren))
        $excludes = array_merge($exChildren, $excludes);

    That’s it. If your blog breaks as a result of this, I’m not responsible.

    Best,

Viewing 5 replies - 1 through 5 (of 5 total)
  • This would be a very desirable feature for the base plug-in, and in fact it’s strange not to be there already. I hope Arne considers making the change. It has always struck me as a key problem for the plugin and the reason I can’t use it and had to roll my own.

    FWIW the above edit does not seem to work in the current release (3.1.6). The following seems to work, at line #1778 (I’ve included the adjacent unmodified lines to show where it goes:

    $excludes = $this->GetOption('b_exclude'); //Excluded posts
    
    // insert begins here
    foreach ($excludes as $exclude) {
      $children = get_pages(array('child_of' => $exclude));
      foreach ($children as $child)
        $exChildren[] = $child->ID;
        }
      if (is_array($exChildren)) $excludes = array_merge($exChildren, $excludes);
    // insert ends here
    
    $exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats

    As msafi said above, try at your own risk. ??

    Thread Starter M.K. Safi

    (@msafi)

    spinality,

    I was reluctant to update for fear I’d have to think some more to get the functionality back. Thanks to you, I don’t have to think ??

    Best,

    Could someone translate this for use by non programmers???
    You show lines to insert but, to my eyes, don’t tell how to use it.
    Here’s a page excluder which DOES speak to ordinary mortals.
    https://www.ads-software.com/extend/plugins/exclude-pages/

    Thread Starter M.K. Safi

    (@msafi)

    mugger,

    This thread is about modifying a plugin called Google XML Sitemaps. The link you provided doesn’t seem related to this at all, which leads me to think that you’re in the wrong place.

    Best,

    -ms

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Google XML Sitemaps] Exclude Pages By Parent ID’ is closed to new replies.