WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. MK Safi
    Member
    Posted 5 years 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 4 years 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 4 years 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. MK Safi
    Member
    Posted 4 years 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,

  5. mugger
    Member
    Posted 4 years ago #

    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.
    http://wordpress.org/extend/plugins/exclude-pages/

  6. MK Safi
    Member
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic