Forums

[Plugin: Google XML Sitemaps] Exclude Pages By Parent ID (4 posts)

  1. msafi
    Member
    Posted 3 months ago #

    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,

  2. spinality
    Member
    Posted 2 months ago #

    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.

  3. spinality
    Member
    Posted 2 months ago #

    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. :)

  4. msafi
    Member
    Posted 2 months ago #

    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,

Reply

You must log in to post.

About this Topic